This repository was archived by the owner on Mar 26, 2026. It is now read-only.
Description For the function get_mtls_endpoint_and_cert_source , consider updating the name and refactor the code for better code readability and maintainability:
Suggested code change:
@classmethod
def validate_environment_variables (cls , use_client_cert , use_mtls_endpoint ):
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 auth_exceptions .MutualTLSChannelError ("Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" )
@classmethod
def get_client_cert_source (cls , client_options , use_client_cert ):
client_cert_source = None
if use_client_cert == "true" :
if client_options .client_cert_source :
client_cert_source = client_options .client_cert_source
elif mtls .has_default_client_cert_source ():
client_cert_source = mtls .default_client_cert_source ()
return client_cert_source
@classmethod
def get_api_endpoint (cls , api_override , use_mtls_endpoint , client_cert_source ):
if api_override is not None :
api_endpoint = api_override
elif use_mtls_endpoint == "always" or (use_mtls_endpoint == "auto" and client_cert_source ):
api_endpoint = cls .DEFAULT_MTLS_ENDPOINT
else :
# return the default api endpoint
return api_endpoint
@classmethod
def get_mtls_endpoint_and_cert_source (cls , client_options : Optional [GoogleClientOptions ] = None ) -> Tuple [str , Callable [[], Tuple [bytes , bytes ]], Optional [str ]]:
if client_options is None :
client_options = GoogleClientOptions ()
use_client_cert = os .getenv ("GOOGLE_API_USE_CLIENT_CERTIFICATE" , "false" )
use_mtls_endpoint = os .getenv ("GOOGLE_API_USE_MTLS_ENDPOINT" , "auto" )
cls .validate_environment_variables (use_client_cert , use_mtls_endpoint )
client_cert_source = cls .get_client_cert_source (client_options , use_client_cert )
api_endpoint = cls .get_api_endpoint (client_options .api_override , use_mtls_endpoint , client_cert_source )
return api_endpoint , client_cert_source
The function name should also be updated to get_api_endpoint_and_cert_source since that is essentially what it's returning.
Also consider refactoring the code in here for consistency: Ads template
Reactions are currently unavailable
For the function get_mtls_endpoint_and_cert_source, consider updating the name and refactor the code for better code readability and maintainability:
Suggested code change:
The function name should also be updated to
get_api_endpoint_and_cert_sourcesince that is essentially what it's returning.Also consider refactoring the code in here for consistency: Ads template