diff --git a/bigquery/google/cloud/bigquery/client.py b/bigquery/google/cloud/bigquery/client.py index e98f390ff616..a00a1a28abaa 100644 --- a/bigquery/google/cloud/bigquery/client.py +++ b/bigquery/google/cloud/bigquery/client.py @@ -15,7 +15,7 @@ """Client for interacting with the Google BigQuery API.""" -from google.cloud.client import JSONClient +from google.cloud.client import ClientWithProject from google.cloud.bigquery._http import Connection from google.cloud.bigquery.dataset import Dataset from google.cloud.bigquery.job import CopyJob @@ -50,7 +50,7 @@ def from_api_repr(cls, resource): resource['id'], resource['numericId'], resource['friendlyName']) -class Client(JSONClient): +class Client(ClientWithProject): """Client to bundle configuration needed for API requests. :type project: str diff --git a/core/google/cloud/_helpers.py b/core/google/cloud/_helpers.py index f2fceb8526ed..22ed39b24ffc 100644 --- a/core/google/cloud/_helpers.py +++ b/core/google/cloud/_helpers.py @@ -512,7 +512,7 @@ def _name_from_project_path(path, project, template): return match.group('name') -def make_secure_channel(credentials, user_agent, host, extra_options=None): +def make_secure_channel(credentials, user_agent, host, extra_options=()): """Makes a secure channel for an RPC service. Uses / depends on gRPC. @@ -538,10 +538,7 @@ def make_secure_channel(credentials, user_agent, host, extra_options=None): http_request = google_auth_httplib2.Request(http=httplib2.Http()) user_agent_option = ('grpc.primary_user_agent', user_agent) - if extra_options is not None: - options = (user_agent_option,) + extra_options - else: - options = (user_agent_option,) + options = (user_agent_option,) + extra_options return google.auth.transport.grpc.secure_authorized_channel( credentials, http_request, @@ -550,7 +547,7 @@ def make_secure_channel(credentials, user_agent, host, extra_options=None): def make_secure_stub(credentials, user_agent, stub_class, host, - extra_options=None): + extra_options=()): """Makes a secure stub for an RPC service. Uses / depends on gRPC. diff --git a/core/google/cloud/client.py b/core/google/cloud/client.py index 7a14e03f763a..01dec6498b9e 100644 --- a/core/google/cloud/client.py +++ b/core/google/cloud/client.py @@ -129,11 +129,8 @@ def _determine_default(project): return _determine_default_project(project) -class JSONClient(Client, _ClientProjectMixin): - """Client for Google JSON-based API. - - Assumes such APIs use the ``project`` and the client needs to store this - value. +class ClientWithProject(Client, _ClientProjectMixin): + """Client that also stores a project. :type project: str :param project: the project which the client acts on behalf of. If not diff --git a/core/unit_tests/test__helpers.py b/core/unit_tests/test__helpers.py index e0642780c0a4..ced80e92278f 100644 --- a/core/unit_tests/test__helpers.py +++ b/core/unit_tests/test__helpers.py @@ -789,7 +789,7 @@ def mock_channel(*args, **kwargs): credentials = object() user_agent = 'you-sir-age-int' host = 'localhost' - extra_options = {'extra_options': None} + extra_options = {'extra_options': ()} with _Monkey(MUT, make_secure_channel=mock_channel): stub = self._call_fut(credentials, user_agent, stub_class, host) diff --git a/core/unit_tests/test_client.py b/core/unit_tests/test_client.py index a503891bc0c6..e3e58f238d85 100644 --- a/core/unit_tests/test_client.py +++ b/core/unit_tests/test_client.py @@ -104,13 +104,13 @@ def test_from_service_account_json_bad_args(self): mock.sentinel.filename, credentials=mock.sentinel.credentials) -class TestJSONClient(unittest.TestCase): +class TestClientWithProject(unittest.TestCase): @staticmethod def _get_target_class(): - from google.cloud.client import JSONClient + from google.cloud.client import ClientWithProject - return JSONClient + return ClientWithProject def _make_one(self, *args, **kw): return self._get_target_class()(*args, **kw) diff --git a/dns/google/cloud/dns/client.py b/dns/google/cloud/dns/client.py index 429ebe941c04..3d33aa4711b2 100644 --- a/dns/google/cloud/dns/client.py +++ b/dns/google/cloud/dns/client.py @@ -15,13 +15,13 @@ """Client for interacting with the Google Cloud DNS API.""" -from google.cloud.client import JSONClient +from google.cloud.client import ClientWithProject from google.cloud.dns.connection import Connection from google.cloud.dns.zone import ManagedZone from google.cloud.iterator import HTTPIterator -class Client(JSONClient): +class Client(ClientWithProject): """Client to bundle configuration needed for API requests. :type project: str diff --git a/logging/google/cloud/logging/client.py b/logging/google/cloud/logging/client.py index 77e762e6c808..2a29c0d03b49 100644 --- a/logging/google/cloud/logging/client.py +++ b/logging/google/cloud/logging/client.py @@ -29,7 +29,7 @@ else: _HAVE_GAX = True -from google.cloud.client import JSONClient +from google.cloud.client import ClientWithProject from google.cloud.environment_vars import DISABLE_GRPC from google.cloud.logging._http import Connection from google.cloud.logging._http import _LoggingAPI as JSONLoggingAPI @@ -59,7 +59,7 @@ """Environment variable set in a Google Container Engine environment.""" -class Client(JSONClient): +class Client(ClientWithProject): """Client to bundle configuration needed for API requests. :type project: str diff --git a/monitoring/google/cloud/monitoring/client.py b/monitoring/google/cloud/monitoring/client.py index ccf3d0866d86..aec2144aa73e 100644 --- a/monitoring/google/cloud/monitoring/client.py +++ b/monitoring/google/cloud/monitoring/client.py @@ -31,7 +31,7 @@ import datetime from google.cloud._helpers import _datetime_to_rfc3339 -from google.cloud.client import JSONClient +from google.cloud.client import ClientWithProject from google.cloud.monitoring.connection import Connection from google.cloud.monitoring.group import Group from google.cloud.monitoring.metric import Metric @@ -47,7 +47,7 @@ _UTCNOW = datetime.datetime.utcnow # To be replaced by tests. -class Client(JSONClient): +class Client(ClientWithProject): """Client to bundle configuration needed for API requests. :type project: str diff --git a/pubsub/google/cloud/pubsub/client.py b/pubsub/google/cloud/pubsub/client.py index a66aebc5db95..60c4a510d1fa 100644 --- a/pubsub/google/cloud/pubsub/client.py +++ b/pubsub/google/cloud/pubsub/client.py @@ -16,7 +16,7 @@ import os -from google.cloud.client import JSONClient +from google.cloud.client import ClientWithProject from google.cloud.environment_vars import DISABLE_GRPC from google.cloud.pubsub._http import Connection from google.cloud.pubsub._http import _PublisherAPI as JSONPublisherAPI @@ -43,7 +43,7 @@ _USE_GAX = _HAVE_GAX and not _DISABLE_GAX -class Client(JSONClient): +class Client(ClientWithProject): """Client to bundle configuration needed for API requests. :type project: str diff --git a/runtimeconfig/google/cloud/runtimeconfig/client.py b/runtimeconfig/google/cloud/runtimeconfig/client.py index d74e5349db3e..0dc95e655dd8 100644 --- a/runtimeconfig/google/cloud/runtimeconfig/client.py +++ b/runtimeconfig/google/cloud/runtimeconfig/client.py @@ -15,12 +15,12 @@ """Client for interacting with the Google Cloud RuntimeConfig API.""" -from google.cloud.client import JSONClient +from google.cloud.client import ClientWithProject from google.cloud.runtimeconfig.connection import Connection from google.cloud.runtimeconfig.config import Config -class Client(JSONClient): +class Client(ClientWithProject): """Client to bundle configuration needed for API requests. :type project: str diff --git a/storage/google/cloud/storage/client.py b/storage/google/cloud/storage/client.py index d7697a4323eb..624954e6e7f0 100644 --- a/storage/google/cloud/storage/client.py +++ b/storage/google/cloud/storage/client.py @@ -16,7 +16,7 @@ from google.cloud._helpers import _LocalStack -from google.cloud.client import JSONClient +from google.cloud.client import ClientWithProject from google.cloud.exceptions import NotFound from google.cloud.iterator import HTTPIterator from google.cloud.storage._http import Connection @@ -24,7 +24,7 @@ from google.cloud.storage.bucket import Bucket -class Client(JSONClient): +class Client(ClientWithProject): """Client to bundle configuration needed for API requests. :type project: str diff --git a/vision/google/cloud/vision/client.py b/vision/google/cloud/vision/client.py index 89d9829d16fa..4d0a5771300c 100644 --- a/vision/google/cloud/vision/client.py +++ b/vision/google/cloud/vision/client.py @@ -16,7 +16,7 @@ import os -from google.cloud.client import JSONClient +from google.cloud.client import ClientWithProject from google.cloud.environment_vars import DISABLE_GRPC from google.cloud.vision._gax import _GAPICVisionAPI @@ -28,7 +28,7 @@ _USE_GAX = not os.getenv(DISABLE_GRPC, False) -class Client(JSONClient): +class Client(ClientWithProject): """Client to bundle configuration needed for API requests. :type project: str