Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions google/api_core/operations_v1/abstract_operations_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,22 @@ def __init__(
client_options = client_options_lib.ClientOptions()

# Create SSL credentials for mutual TLS if needed.
use_client_cert = os.getenv(
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
).lower()
if use_client_cert not in ("true", "false"):
raise ValueError(
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
)
if hasattr(mtls, "should_use_client_cert"):
use_client_cert = mtls.should_use_client_cert()
else:
# if unsupported, fallback to reading from env var
use_client_cert_str = os.getenv(
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
).lower()
if use_client_cert_str not in ("true", "false"):
raise ValueError(
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"
" either `true` or `false`"
)
use_client_cert = use_client_cert_str == "true"
client_cert_source_func = None
is_mtls = False
if use_client_cert == "true":
if use_client_cert:
if client_options.client_cert_source:
is_mtls = True
client_cert_source_func = client_options.client_cert_source
Expand Down
10 changes: 7 additions & 3 deletions tests/unit/operations_v1/test_operations_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,16 @@ def test_operations_client_client_options(
with pytest.raises(MutualTLSChannelError):
client = client_class()

# Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
# Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value and
# should_use_client_cert is unavailable.
with mock.patch.dict(
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
):
with pytest.raises(ValueError):
client = client_class()
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
pytest.skip(
"The should_use_client_cert function is available in this "
"version of google-auth. Skipping this test."
)

# Check the case quota_project_id is provided
options = client_options.ClientOptions(quota_project_id="octopus")
Expand Down
Loading