Skip to content

chore(generator): move _use_client_cert_effective to _compat.py.j2 - #17963

Open
hebaalazzeh wants to merge 7 commits into
mainfrom
remove-use-client-cert-effective
Open

chore(generator): move _use_client_cert_effective to _compat.py.j2#17963
hebaalazzeh wants to merge 7 commits into
mainfrom
remove-use-client-cert-effective

Conversation

@hebaalazzeh

@hebaalazzeh hebaalazzeh commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

We move _use_client_cert_effective and the associated tests to _compat.py.j2. This will reduce duplication in packages that have multiple services and this can we removed in the future when we bump the minimum version of google-auth.

@hebaalazzeh hebaalazzeh self-assigned this Jul 31, 2026

@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 removes the internal helper method _use_client_cert_effective from the client templates and replaces its calls with mtls.should_use_client_cert(). Additionally, all corresponding unit tests for the removed method have been cleaned up across the test templates and golden files. I have no feedback to provide as the changes are clean and consistent.

@hebaalazzeh hebaalazzeh changed the title chore(generator): remove _use_client_cert_effective from gapic-generator chore(generator): move _use_client_cert_effective to _compat.py.j2 Jul 31, 2026
@hebaalazzeh
hebaalazzeh marked this pull request as ready for review July 31, 2026 18:43
@hebaalazzeh
hebaalazzeh requested a review from a team as a code owner July 31, 2026 18:43
"""Returns whether client certificate should be used for mTLS."""
if hasattr(mtls, "should_use_client_cert"):
return mtls.should_use_client_cert()
else:

@daniel-sanche daniel-sanche Jul 31, 2026

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.

I thought the pattern you were using for this file was to try importing from the helper library, and provide the backup implementation if there's an ImportError. Do you plan to use hasattr for everything instead now?

else:
use_client_cert_str = os.getenv(
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
).lower()

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.

The mtls implementation is a bit different, using two env vars. Should we try to match here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed matched the implementation

raise EmptyUniverseError()
return resolved

def use_client_cert_effective() -> bool:

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.

The mtls implementation is called should_use_client_cert. Should we use the same name here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed updated name

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.

2 participants