From a58293601d6da90c499d404e634a979a6cae9708 Mon Sep 17 00:00:00 2001 From: Dov Shlachter Date: Thu, 4 Jun 2020 18:04:11 -0700 Subject: [PATCH 1/2] feat(client_options): add new client options 'quota_project_id', 'scopes', and 'credentials_file' Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> --- google/api_core/client_options.py | 26 +++++++++++++++++------- tests/unit/test_client_options.py | 33 ++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/google/api_core/client_options.py b/google/api_core/client_options.py index b6d9384d..d272f40f 100644 --- a/google/api_core/client_options.py +++ b/google/api_core/client_options.py @@ -53,15 +53,20 @@ class ClientOptions(object): """Client Options used to set options on clients. Args: - api_endpoint (str): The desired API endpoint, e.g., compute.googleapis.com - client_cert_source (Callable[[], (bytes, bytes)]): An optional callback + api_endpoint (Optional[str]): The desired API endpoint, e.g., + compute.googleapis.com + client_cert_source (Optional[Callable[[], (bytes, bytes)]]): A callback which returns client certificate bytes and private key bytes both in PEM format. ``client_cert_source`` and ``client_encrypted_cert_source`` are mutually exclusive. - client_encrypted_cert_source (Callable[[], (str, str, bytes)]): An optional - callback which returns client certificate file path, encrypted private - key file path, and the passphrase bytes.``client_cert_source`` and - ``client_encrypted_cert_source`` are mutually exclusive. + client_encrypted_cert_source (Optional[Callable[[], (str, str, bytes)]]): + A callback which returns client certificate file path, encrypted + private key file path, and the passphrase bytes.``client_cert_source`` + and ``client_encrypted_cert_source`` are mutually exclusive. + quota_project_id (Optional[str]): A project name that a client's + quota belongs to. + credentials_file (Optional[str]): A path to a file storing credentials. + scopes (Optional[Sequence[str]]): OAuth access token override scopes. Raises: ValueError: If both ``client_cert_source`` and ``client_encrypted_cert_source`` @@ -73,6 +78,9 @@ def __init__( api_endpoint=None, client_cert_source=None, client_encrypted_cert_source=None, + quota_project_id=None, + credentials_file=None, + scopes=None, ): if client_cert_source and client_encrypted_cert_source: raise ValueError( @@ -81,6 +89,9 @@ def __init__( self.api_endpoint = api_endpoint self.client_cert_source = client_cert_source self.client_encrypted_cert_source = client_encrypted_cert_source + self.quota_project_id = quota_project_id + self.credentials_file = credentials_file + self.scopes = scopes def __repr__(self): return "ClientOptions: " + repr(self.__dict__) @@ -90,7 +101,8 @@ def from_dict(options): """Construct a client options object from a dictionary. Args: - options (dict): A dictionary with client options. + options (Dict[str, Any]): A dictionary with client options. + See the docstring for ClientOptions for details on valid arguments. """ client_options = ClientOptions() diff --git a/tests/unit/test_client_options.py b/tests/unit/test_client_options.py index 67c4f6b4..1581c56e 100644 --- a/tests/unit/test_client_options.py +++ b/tests/unit/test_client_options.py @@ -28,11 +28,24 @@ def get_client_encrypted_cert(): def test_constructor(): options = client_options.ClientOptions( - api_endpoint="foo.googleapis.com", client_cert_source=get_client_cert + api_endpoint="foo.googleapis.com", + client_cert_source=get_client_cert, + quota_project_id="quote-proj", + credentials_file="path/to/credentials.json", + scopes=[ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ] ) assert options.api_endpoint == "foo.googleapis.com" assert options.client_cert_source() == (b"cert", b"key") + assert options.quota_project_id == "quote-proj" + assert options.credentials_file == "path/to/credentials.json" + assert options.scopes == [ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ] def test_constructor_with_encrypted_cert_source(): @@ -61,12 +74,26 @@ def test_constructor_with_both_cert_sources(): def test_from_dict(): options = client_options.from_dict( - {"api_endpoint": "foo.googleapis.com", "client_cert_source": get_client_cert} + { + "api_endpoint": "foo.googleapis.com", + "client_cert_source": get_client_cert, + "quota_project_id": "quote-proj", + "credentials_file": "path/to/credentials.json", + "scopes": [ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ] + } ) assert options.api_endpoint == "foo.googleapis.com" - # assert options.client_cert_source == get_client_cert assert options.client_cert_source() == (b"cert", b"key") + assert options.quota_project_id == "quote-proj" + assert options.credentials_file == "path/to/credentials.json" + assert options.scopes == [ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ] def test_from_dict_bad_argument(): From d1937ba1ac80ece8cb0fed7155a881a8f3ba5e78 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Thu, 4 Jun 2020 18:27:12 -0700 Subject: [PATCH 2/2] chore: release 1.19.0 (#39) * updated CHANGELOG.md [ci skip] * updated setup.cfg [ci skip] * updated setup.py Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 7 +++++++ setup.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 123c1f28..cbc6a6c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ [1]: https://pypi.org/project/google-api-core/#history +## [1.19.0](https://www.github.com/googleapis/python-api-core/compare/v1.18.0...v1.19.0) (2020-06-05) + + +### Features + +* **client_options:** add new client options 'quota_project_id', 'scopes', and 'credentials_file' ([a582936](https://www.github.com/googleapis/python-api-core/commit/a58293601d6da90c499d404e634a979a6cae9708)) + ## [1.18.0](https://www.github.com/googleapis/python-api-core/compare/v1.17.0...v1.18.0) (2020-06-04) diff --git a/setup.py b/setup.py index 1f5f4ade..cea8a857 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ name = "google-api-core" description = "Google API client core library" -version = "1.18.0" +version = "1.19.0" # Should be one of: # 'Development Status :: 3 - Alpha' # 'Development Status :: 4 - Beta'