Skip to content

Commit e4eaec0

Browse files
feat: add client_encryped_cert_source to ClientOptions (#31)
1 parent a82f289 commit e4eaec0

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

google/api_core/client_options.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,31 @@ class ClientOptions(object):
5656
api_endpoint (str): The desired API endpoint, e.g., compute.googleapis.com
5757
client_cert_source (Callable[[], (bytes, bytes)]): An optional callback
5858
which returns client certificate bytes and private key bytes both in
59-
PEM format.
59+
PEM format. ``client_cert_source`` and ``client_encrypted_cert_source``
60+
are mutually exclusive.
61+
client_encrypted_cert_source (Callable[[], (str, str, bytes)]): An optional
62+
callback which returns client certificate file path, encrypted private
63+
key file path, and the passphrase bytes.``client_cert_source`` and
64+
``client_encrypted_cert_source`` are mutually exclusive.
65+
66+
Raises:
67+
ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source``
68+
are provided.
6069
"""
6170

62-
def __init__(self, api_endpoint=None, client_cert_source=None):
71+
def __init__(
72+
self,
73+
api_endpoint=None,
74+
client_cert_source=None,
75+
client_encrypted_cert_source=None,
76+
):
77+
if client_cert_source and client_encrypted_cert_source:
78+
raise ValueError(
79+
"client_cert_source and client_encrypted_cert_source are mutually exclusive"
80+
)
6381
self.api_endpoint = api_endpoint
6482
self.client_cert_source = client_cert_source
83+
self.client_encrypted_cert_source = client_encrypted_cert_source
6584

6685
def __repr__(self):
6786
return "ClientOptions: " + repr(self.__dict__)

tests/unit/test_client_options.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def get_client_cert():
2121
return b"cert", b"key"
2222

2323

24+
def get_client_encrypted_cert():
25+
return "cert_path", "key_path", b"passphrase"
26+
27+
2428
def test_constructor():
2529

2630
options = client_options.ClientOptions(
@@ -31,6 +35,30 @@ def test_constructor():
3135
assert options.client_cert_source() == (b"cert", b"key")
3236

3337

38+
def test_constructor_with_encrypted_cert_source():
39+
40+
options = client_options.ClientOptions(
41+
api_endpoint="foo.googleapis.com",
42+
client_encrypted_cert_source=get_client_encrypted_cert,
43+
)
44+
45+
assert options.api_endpoint == "foo.googleapis.com"
46+
assert options.client_encrypted_cert_source() == (
47+
"cert_path",
48+
"key_path",
49+
b"passphrase",
50+
)
51+
52+
53+
def test_constructor_with_both_cert_sources():
54+
with pytest.raises(ValueError):
55+
client_options.ClientOptions(
56+
api_endpoint="foo.googleapis.com",
57+
client_cert_source=get_client_cert,
58+
client_encrypted_cert_source=get_client_encrypted_cert,
59+
)
60+
61+
3462
def test_from_dict():
3563
options = client_options.from_dict(
3664
{"api_endpoint": "foo.googleapis.com", "client_cert_source": get_client_cert}
@@ -57,6 +85,6 @@ def test_repr():
5785

5886
assert (
5987
repr(options)
60-
== "ClientOptions: {'api_endpoint': 'foo.googleapis.com', 'client_cert_source': None}"
61-
or "ClientOptions: {'client_cert_source': None, 'api_endpoint': 'foo.googleapis.com'}"
88+
== "ClientOptions: {'api_endpoint': 'foo.googleapis.com', 'client_cert_source': None, 'client_encrypted_cert_source': None}"
89+
or "ClientOptions: {'client_encrypted_cert_source': None, 'client_cert_source': None, 'api_endpoint': 'foo.googleapis.com'}"
6290
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy