chore(generator): move get_client_cert_source to compat layer - #17996
chore(generator): move get_client_cert_source to compat layer#17996hebaalazzeh wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the client certificate source retrieval logic by extracting the _get_client_cert_source static method from the service client template into a standalone helper function get_client_cert_source within the compatibility module, updating the generated clients, tests, and golden files accordingly. The review feedback suggests improving the helper function's docstring and type annotations to correctly specify Callable types instead of bytes, and updating the unit tests to pass a boolean True instead of the string "true" to avoid static type-checking failures.
| 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 get_client_cert_source(None, True) is mock_default_cert_source | ||
| assert get_client_cert_source(mock_provided_cert_source, "true") is mock_provided_cert_source |
There was a problem hiding this comment.
If get_client_cert_source is type-hinted with use_cert_flag: bool, passing the string "true" here can cause static type checkers (like mypy) to fail when type-checking the generated test files. It is safer and more idiomatic to use the boolean True instead.
assert get_client_cert_source(mock_provided_cert_source, True) is mock_provided_cert_source
We move
_get_client_cert_sourceand its associated unit tests into_compat.py.j2asget_client_cert_source.This reduces code duplication in packages that have multiple services. This fallback helper can be removed in the future once we bump the minimum supported version of
google-authto>= 2.43.0.Towards: #17883