Skip to content

chore(generator): move get_client_cert_source to compat layer - #17996

Open
hebaalazzeh wants to merge 3 commits into
mainfrom
chore/move-get-client-cert-source
Open

chore(generator): move get_client_cert_source to compat layer#17996
hebaalazzeh wants to merge 3 commits into
mainfrom
chore/move-get-client-cert-source

Conversation

@hebaalazzeh

@hebaalazzeh hebaalazzeh commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

We move _get_client_cert_source and its associated unit tests into _compat.py.j2 as get_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-auth to >= 2.43.0.

Towards: #17883

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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

@hebaalazzeh hebaalazzeh self-assigned this Aug 4, 2026
@hebaalazzeh
hebaalazzeh marked this pull request as ready for review August 5, 2026 05:34
@hebaalazzeh
hebaalazzeh requested a review from a team as a code owner August 5, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant