Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 10 additions & 6 deletions packages/google-api-core/google/api_core/client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ def __init__(
if credentials_file is not None:
warnings.warn(general_helpers._CREDENTIALS_FILE_WARNING, DeprecationWarning)

if client_cert_source and client_encrypted_cert_source:
raise ValueError(
"client_cert_source and client_encrypted_cert_source are mutually exclusive"
)
if api_key and credentials_file:
raise ValueError("api_key and credentials_file are mutually exclusive")
self.api_endpoint = api_endpoint
self.client_cert_source = client_cert_source
self.client_encrypted_cert_source = client_encrypted_cert_source
Expand All @@ -144,6 +138,15 @@ def __init__(
self.api_audience = api_audience
self.universe_domain = universe_domain
self.tracer_provider = tracer_provider
self._validate_options()

def _validate_options(self) -> None:
if self.client_cert_source and self.client_encrypted_cert_source:
raise ValueError(
"client_cert_source and client_encrypted_cert_source are mutually exclusive"
)
if self.api_key and self.credentials_file:
raise ValueError("api_key and credentials_file are mutually exclusive")

def __repr__(self) -> str:
return "ClientOptions: " + repr(self.__dict__)
Expand All @@ -165,4 +168,5 @@ def from_dict(options: Mapping[str, object]) -> ClientOptions:
else:
raise ValueError("ClientOptions does not accept an option '" + key + "'")

client_options._validate_options()
return client_options
20 changes: 20 additions & 0 deletions packages/google-api-core/tests/unit/test_client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ def test_from_dict_bad_argument():
)


def test_from_dict_with_both_cert_sources():
with pytest.raises(ValueError):
client_options.from_dict(
{
"client_cert_source": get_client_cert,
"client_encrypted_cert_source": get_client_encrypted_cert,
}
)


def test_from_dict_with_both_api_key_and_credentials_file():
with pytest.raises(ValueError):
client_options.from_dict(
{
"api_key": "api-key",
"credentials_file": "path/to/credentials.json",
}
)


def test_repr():
expected_keys = set(
[
Expand Down
Loading