Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(google-auth): Handle missing pyOpenSSL for inferred mTLS#16921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -448,6 +448,22 @@ def client_cert_callback(): | ||||||||
| return crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey) | ||||||||
| def _get_use_client_cert_env(): | ||||||||
| """Returns the configured client certificate opt-in environment value.""" | ||||||||
| use_client_cert = getenv(environment_vars.GOOGLE_API_USE_CLIENT_CERTIFICATE) | ||||||||
| if use_client_cert is None or use_client_cert == "": | ||||||||
| use_client_cert = getenv( | ||||||||
| environment_vars.CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE | ||||||||
| ) | ||||||||
| return use_client_cert | ||||||||
| def _is_client_cert_explicitly_enabled(): | ||||||||
| """Returns True if an environment variable explicitly enables client certs.""" | ||||||||
| use_client_cert = _get_use_client_cert_env() | ||||||||
| return bool(use_client_cert and use_client_cert.lower() == "true") | ||||||||
Comment on lines
+463
to
+464
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified by inlining the environment variable check and using a default empty string to handle the
Suggested change
| ||||||||
| def check_use_client_cert(): | ||||||||
| """Returns boolean for whether the client certificate should be used for mTLS. | ||||||||
| @@ -462,11 +478,7 @@ def check_use_client_cert(): | ||||||||
| Returns: | ||||||||
| bool: Whether the client certificate should be used for mTLS connection. | ||||||||
| """ | ||||||||
| use_client_cert = getenv(environment_vars.GOOGLE_API_USE_CLIENT_CERTIFICATE) | ||||||||
| if use_client_cert is None or use_client_cert == "": | ||||||||
| use_client_cert = getenv( | ||||||||
| environment_vars.CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATE | ||||||||
| ) | ||||||||
| use_client_cert = _get_use_client_cert_env() | ||||||||
| # Check if the value of GOOGLE_API_USE_CLIENT_CERTIFICATE is set. | ||||||||
| if use_client_cert: | ||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic for falling back between environment variables can be simplified using the
oroperator, which is more idiomatic in Python for handlingNoneor empty string fallbacks.