Skip to content

Commit b7ca762

Browse files
committed
clean up
1 parent 275244d commit b7ca762

13 files changed

Lines changed: 40 additions & 689 deletions

File tree

  • packages/gapic-generator
    • gapic/templates/%namespace/%name_%version/%sub/services/%service
    • tests/integration/goldens
      • asset/google/cloud/asset_v1/services/asset_service
      • credentials/google/iam/credentials_v1/services/iam_credentials
      • eventarc/google/cloud/eventarc_v1/services/eventarc
      • logging_internal/google/cloud/logging_v2/services
      • logging/google/cloud/logging_v2/services
      • redis_selective/google/cloud/redis_v1/services/cloud_redis
      • redis/google/cloud/redis_v1/services/cloud_redis
      • storagebatchoperations/google/cloud/storagebatchoperations_v1/services/storage_batch_operations

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ from google.api_core import exceptions as core_exceptions
3030
from google.api_core import extended_operation
3131
{% endif %}
3232
from google.api_core import gapic_v1
33-
from {{package_path}} import _compat as client_utils
33+
from {{package_path}}._compat import determine_domain, get_api_endpoint, get_default_mtls_endpoint
3434
from google.api_core import retry as retries
3535
from google.auth import credentials as ga_credentials # type: ignore
3636
from google.auth.transport import mtls # type: ignore
@@ -358,55 +358,6 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
358358
client_cert_source = mtls.default_client_cert_source()
359359
return client_cert_source
360360

361-
@staticmethod
362-
def _get_api_endpoint(
363-
api_override: Optional[str],
364-
client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]],
365-
universe_domain: str,
366-
use_mtls_endpoint: str,
367-
) -> Optional[str]:
368-
"""Return the API endpoint used by the client.
369-
370-
Args:
371-
api_override (Optional[str]): The API endpoint override. If specified, this is always
372-
the return value of this function and the other arguments are not used.
373-
client_cert_source (Union[Callable[[], Tuple[bytes, bytes]], None]): The client certificate source used by the client.
374-
universe_domain (str): The universe domain used by the client.
375-
use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
376-
Possible values are "always", "auto", or "never".
377-
378-
Returns:
379-
Optional[str]: The API endpoint to be used by the client.
380-
"""
381-
return client_utils.get_api_endpoint(
382-
api_override,
383-
client_cert_source,
384-
universe_domain,
385-
use_mtls_endpoint,
386-
{{ service.client_name }}._DEFAULT_UNIVERSE,
387-
{{ service.client_name }}.DEFAULT_MTLS_ENDPOINT,
388-
{{ service.client_name }}._DEFAULT_ENDPOINT_TEMPLATE,
389-
)
390-
391-
@staticmethod
392-
def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str:
393-
"""Return the universe domain used by the client.
394-
395-
Args:
396-
client_universe_domain (Optional[str]): The universe domain configured via the client options.
397-
universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
398-
399-
Returns:
400-
str: The universe domain to be used by the client.
401-
402-
Raises:
403-
ValueError: If the universe domain is an empty string.
404-
"""
405-
return client_utils.get_universe_domain(
406-
client_universe_domain,
407-
universe_domain_env,
408-
default_universe={{ service.client_name }}._DEFAULT_UNIVERSE,
409-
)
410361

411362
def _validate_universe_domain(self):
412363
"""Validates client's and credentials' universe domains are consistent.
@@ -568,7 +519,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
568519

569520
self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = {{ service.client_name }}._read_environment_variables()
570521
self._client_cert_source = {{ service.client_name }}._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert)
571-
self._universe_domain = {{ service.client_name }}._get_universe_domain(universe_domain_opt, self._universe_domain_env)
522+
self._universe_domain = determine_domain(universe_domain_opt, self._universe_domain_env)
572523
self._api_endpoint: str = "" # updated below, depending on `transport`
573524

574525
# Initialize the universe domain validation.
@@ -599,8 +550,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
599550
self._transport = cast({{ service.name }}Transport, transport)
600551
self._api_endpoint = self._transport.host
601552

602-
self._api_endpoint = (self._api_endpoint or
603-
{{ service.client_name }}._get_api_endpoint(
553+
self._api_endpoint = (self._api_endpoint or
554+
get_api_endpoint(
604555
self._client_options.api_endpoint,
605556
self._client_cert_source,
606557
self._universe_domain,

packages/gapic-generator/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from google.api_core import client_options as client_options_lib
2828
from google.api_core import exceptions as core_exceptions
2929
from google.api_core import gapic_v1
30-
from google.cloud.asset_v1 import _compat as client_utils
30+
from google.cloud.asset_v1._compat import determine_domain, get_api_endpoint, get_default_mtls_endpoint
3131
from google.api_core import retry as retries
3232
from google.auth import credentials as ga_credentials # type: ignore
3333
from google.auth.transport import mtls # type: ignore
@@ -416,56 +416,6 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag):
416416
client_cert_source = mtls.default_client_cert_source()
417417
return client_cert_source
418418

419-
@staticmethod
420-
def _get_api_endpoint(
421-
api_override: Optional[str],
422-
client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]],
423-
universe_domain: str,
424-
use_mtls_endpoint: str,
425-
) -> Optional[str]:
426-
"""Return the API endpoint used by the client.
427-
428-
Args:
429-
api_override (Optional[str]): The API endpoint override. If specified, this is always
430-
the return value of this function and the other arguments are not used.
431-
client_cert_source (Union[Callable[[], Tuple[bytes, bytes]], None]): The client certificate source used by the client.
432-
universe_domain (str): The universe domain used by the client.
433-
use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
434-
Possible values are "always", "auto", or "never".
435-
436-
Returns:
437-
Optional[str]: The API endpoint to be used by the client.
438-
"""
439-
return client_utils.get_api_endpoint(
440-
api_override,
441-
client_cert_source,
442-
universe_domain,
443-
use_mtls_endpoint,
444-
AssetServiceClient._DEFAULT_UNIVERSE,
445-
AssetServiceClient.DEFAULT_MTLS_ENDPOINT,
446-
AssetServiceClient._DEFAULT_ENDPOINT_TEMPLATE,
447-
)
448-
449-
@staticmethod
450-
def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str:
451-
"""Return the universe domain used by the client.
452-
453-
Args:
454-
client_universe_domain (Optional[str]): The universe domain configured via the client options.
455-
universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
456-
457-
Returns:
458-
str: The universe domain to be used by the client.
459-
460-
Raises:
461-
ValueError: If the universe domain is an empty string.
462-
"""
463-
return client_utils.get_universe_domain(
464-
client_universe_domain,
465-
universe_domain_env,
466-
default_universe=AssetServiceClient._DEFAULT_UNIVERSE,
467-
)
468-
469419
def _validate_universe_domain(self):
470420
"""Validates client's and credentials' universe domains are consistent.
471421
@@ -590,7 +540,7 @@ def __init__(self, *,
590540

591541
self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = AssetServiceClient._read_environment_variables()
592542
self._client_cert_source = AssetServiceClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert)
593-
self._universe_domain = AssetServiceClient._get_universe_domain(universe_domain_opt, self._universe_domain_env)
543+
self._universe_domain = determine_domain(universe_domain_opt, self._universe_domain_env)
594544
self._api_endpoint: str = "" # updated below, depending on `transport`
595545

596546
# Initialize the universe domain validation.
@@ -622,7 +572,7 @@ def __init__(self, *,
622572
self._api_endpoint = self._transport.host
623573

624574
self._api_endpoint = (self._api_endpoint or
625-
AssetServiceClient._get_api_endpoint(
575+
get_api_endpoint(
626576
self._client_options.api_endpoint,
627577
self._client_cert_source,
628578
self._universe_domain,

packages/gapic-generator/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from google.api_core import client_options as client_options_lib
2828
from google.api_core import exceptions as core_exceptions
2929
from google.api_core import gapic_v1
30-
from google.iam.credentials_v1 import _compat as client_utils
30+
from google.iam.credentials_v1._compat import determine_domain, get_api_endpoint, get_default_mtls_endpoint
3131
from google.api_core import retry as retries
3232
from google.auth import credentials as ga_credentials # type: ignore
3333
from google.auth.transport import mtls # type: ignore
@@ -353,56 +353,6 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag):
353353
client_cert_source = mtls.default_client_cert_source()
354354
return client_cert_source
355355

356-
@staticmethod
357-
def _get_api_endpoint(
358-
api_override: Optional[str],
359-
client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]],
360-
universe_domain: str,
361-
use_mtls_endpoint: str,
362-
) -> Optional[str]:
363-
"""Return the API endpoint used by the client.
364-
365-
Args:
366-
api_override (Optional[str]): The API endpoint override. If specified, this is always
367-
the return value of this function and the other arguments are not used.
368-
client_cert_source (Union[Callable[[], Tuple[bytes, bytes]], None]): The client certificate source used by the client.
369-
universe_domain (str): The universe domain used by the client.
370-
use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
371-
Possible values are "always", "auto", or "never".
372-
373-
Returns:
374-
Optional[str]: The API endpoint to be used by the client.
375-
"""
376-
return client_utils.get_api_endpoint(
377-
api_override,
378-
client_cert_source,
379-
universe_domain,
380-
use_mtls_endpoint,
381-
IAMCredentialsClient._DEFAULT_UNIVERSE,
382-
IAMCredentialsClient.DEFAULT_MTLS_ENDPOINT,
383-
IAMCredentialsClient._DEFAULT_ENDPOINT_TEMPLATE,
384-
)
385-
386-
@staticmethod
387-
def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str:
388-
"""Return the universe domain used by the client.
389-
390-
Args:
391-
client_universe_domain (Optional[str]): The universe domain configured via the client options.
392-
universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
393-
394-
Returns:
395-
str: The universe domain to be used by the client.
396-
397-
Raises:
398-
ValueError: If the universe domain is an empty string.
399-
"""
400-
return client_utils.get_universe_domain(
401-
client_universe_domain,
402-
universe_domain_env,
403-
default_universe=IAMCredentialsClient._DEFAULT_UNIVERSE,
404-
)
405-
406356
def _validate_universe_domain(self):
407357
"""Validates client's and credentials' universe domains are consistent.
408358
@@ -527,7 +477,7 @@ def __init__(self, *,
527477

528478
self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = IAMCredentialsClient._read_environment_variables()
529479
self._client_cert_source = IAMCredentialsClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert)
530-
self._universe_domain = IAMCredentialsClient._get_universe_domain(universe_domain_opt, self._universe_domain_env)
480+
self._universe_domain = determine_domain(universe_domain_opt, self._universe_domain_env)
531481
self._api_endpoint: str = "" # updated below, depending on `transport`
532482

533483
# Initialize the universe domain validation.
@@ -559,7 +509,7 @@ def __init__(self, *,
559509
self._api_endpoint = self._transport.host
560510

561511
self._api_endpoint = (self._api_endpoint or
562-
IAMCredentialsClient._get_api_endpoint(
512+
get_api_endpoint(
563513
self._client_options.api_endpoint,
564514
self._client_cert_source,
565515
self._universe_domain,

packages/gapic-generator/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from google.api_core import client_options as client_options_lib
2828
from google.api_core import exceptions as core_exceptions
2929
from google.api_core import gapic_v1
30-
from google.cloud.eventarc_v1 import _compat as client_utils
30+
from google.cloud.eventarc_v1._compat import determine_domain, get_api_endpoint, get_default_mtls_endpoint
3131
from google.api_core import retry as retries
3232
from google.auth import credentials as ga_credentials # type: ignore
3333
from google.auth.transport import mtls # type: ignore
@@ -536,56 +536,6 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag):
536536
client_cert_source = mtls.default_client_cert_source()
537537
return client_cert_source
538538

539-
@staticmethod
540-
def _get_api_endpoint(
541-
api_override: Optional[str],
542-
client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]],
543-
universe_domain: str,
544-
use_mtls_endpoint: str,
545-
) -> Optional[str]:
546-
"""Return the API endpoint used by the client.
547-
548-
Args:
549-
api_override (Optional[str]): The API endpoint override. If specified, this is always
550-
the return value of this function and the other arguments are not used.
551-
client_cert_source (Union[Callable[[], Tuple[bytes, bytes]], None]): The client certificate source used by the client.
552-
universe_domain (str): The universe domain used by the client.
553-
use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
554-
Possible values are "always", "auto", or "never".
555-
556-
Returns:
557-
Optional[str]: The API endpoint to be used by the client.
558-
"""
559-
return client_utils.get_api_endpoint(
560-
api_override,
561-
client_cert_source,
562-
universe_domain,
563-
use_mtls_endpoint,
564-
EventarcClient._DEFAULT_UNIVERSE,
565-
EventarcClient.DEFAULT_MTLS_ENDPOINT,
566-
EventarcClient._DEFAULT_ENDPOINT_TEMPLATE,
567-
)
568-
569-
@staticmethod
570-
def _get_universe_domain(client_universe_domain: Optional[str], universe_domain_env: Optional[str]) -> str:
571-
"""Return the universe domain used by the client.
572-
573-
Args:
574-
client_universe_domain (Optional[str]): The universe domain configured via the client options.
575-
universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
576-
577-
Returns:
578-
str: The universe domain to be used by the client.
579-
580-
Raises:
581-
ValueError: If the universe domain is an empty string.
582-
"""
583-
return client_utils.get_universe_domain(
584-
client_universe_domain,
585-
universe_domain_env,
586-
default_universe=EventarcClient._DEFAULT_UNIVERSE,
587-
)
588-
589539
def _validate_universe_domain(self):
590540
"""Validates client's and credentials' universe domains are consistent.
591541
@@ -710,7 +660,7 @@ def __init__(self, *,
710660

711661
self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = EventarcClient._read_environment_variables()
712662
self._client_cert_source = EventarcClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert)
713-
self._universe_domain = EventarcClient._get_universe_domain(universe_domain_opt, self._universe_domain_env)
663+
self._universe_domain = determine_domain(universe_domain_opt, self._universe_domain_env)
714664
self._api_endpoint: str = "" # updated below, depending on `transport`
715665

716666
# Initialize the universe domain validation.
@@ -742,7 +692,7 @@ def __init__(self, *,
742692
self._api_endpoint = self._transport.host
743693

744694
self._api_endpoint = (self._api_endpoint or
745-
EventarcClient._get_api_endpoint(
695+
get_api_endpoint(
746696
self._client_options.api_endpoint,
747697
self._client_cert_source,
748698
self._universe_domain,

0 commit comments

Comments
 (0)