chore(generator): move read_environment_variables to _compat.py.j2 - #17997
chore(generator): move read_environment_variables to _compat.py.j2#17997hebaalazzeh wants to merge 2 commits into
read_environment_variables to _compat.py.j2#17997Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the environment variable reading logic by moving _read_environment_variables from the service client template into a shared helper function read_environment_variables in _compat.py.j2, and adds corresponding unit tests. The review feedback highlights critical issues: a missing closing parenthesis in _compat.py.j2 that will cause a syntax error, and missing imports for MutualTLSChannelError in both _compat.py.j2 and test_compat.py.j2 which will lead to runtime NameErrors.
| google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT | ||
| is not any of ["auto", "never", "always"]. | ||
| """ | ||
| use_client_cert = should_use_client_cert() |
There was a problem hiding this comment.
| {% set package_path = api.naming.module_namespace|join('.') + "." + api.naming.versioned_module_name %} | ||
| from {{package_path}}._compat import transcode_request | ||
| from {{package_path}}._compat import get_universe_domain, get_api_endpoint, get_default_mtls_endpoint, should_use_client_cert | ||
| from {{package_path}}._compat import get_universe_domain, get_api_endpoint, get_default_mtls_endpoint, should_use_client_cert, read_environment_variables |
There was a problem hiding this comment.
MutualTLSChannelError is used in test_read_environment_variables but is not imported in this test file. Please import it from google.auth.exceptions to avoid a NameError during test execution.
from {{package_path}}._compat import get_universe_domain, get_api_endpoint, get_default_mtls_endpoint, should_use_client_cert, read_environment_variables
from google.auth.exceptions import MutualTLSChannelError
We move
_read_environment_variablesand its associated unit tests into_compat.py.j2asread_environment_variables.This reduces code duplication in packages that have multiple services. In the future, once
should_use_mtls_endpointis added togoogle-auth, we can defer parsingGOOGLE_API_USE_MTLS_ENDPOINTupstream.Towards: #17883