diff --git a/error_reporting/google/cloud/error_reporting/_gapic.py b/error_reporting/google/cloud/error_reporting/_gapic.py index b1925ff6a491..0c6ec9e60a1a 100644 --- a/error_reporting/google/cloud/error_reporting/_gapic.py +++ b/error_reporting/google/cloud/error_reporting/_gapic.py @@ -29,7 +29,9 @@ def make_report_error_api(client): :returns: An Error Reporting API instance. """ gapic_api = report_errors_service_client.ReportErrorsServiceClient( - credentials=client._credentials, client_info=client._client_info + credentials=client._credentials, + client_info=client._client_info, + client_options=client._client_options, ) return _ErrorReportingGapicApi(gapic_api, client.project) diff --git a/error_reporting/google/cloud/error_reporting/_logging.py b/error_reporting/google/cloud/error_reporting/_logging.py index 5eaa4693c96f..29e17b6eb5a9 100644 --- a/error_reporting/google/cloud/error_reporting/_logging.py +++ b/error_reporting/google/cloud/error_reporting/_logging.py @@ -54,11 +54,27 @@ class _ErrorReportingLoggingAPI(object): requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own library or partner tool. + + :type client_options: :class:`~google.api_core.client_options.ClientOptions` + or :class:`dict` + :param client_options: (Optional) Client options used to set user options + on the client. API Endpoint should be set through client_options. """ - def __init__(self, project, credentials=None, _http=None, client_info=None): + def __init__( + self, + project, + credentials=None, + _http=None, + client_info=None, + client_options=None, + ): self.logging_client = google.cloud.logging.client.Client( - project, credentials, _http=_http, client_info=client_info + project, + credentials, + _http=_http, + client_info=client_info, + client_options=client_options, ) def report_error_event(self, error_report): diff --git a/error_reporting/google/cloud/error_reporting/client.py b/error_reporting/google/cloud/error_reporting/client.py index 4fdae4c69e25..629455198dd6 100644 --- a/error_reporting/google/cloud/error_reporting/client.py +++ b/error_reporting/google/cloud/error_reporting/client.py @@ -143,6 +143,11 @@ class Client(ClientWithProject): you only need to set this if you're developing your own library or partner tool. + :type client_options: :class:`~google.api_core.client_options.ClientOptions` + or :class:`dict` + :param client_options: (Optional) Client options used to set user options + on the client. API Endpoint should be set through client_options. + :raises: :class:`ValueError` if the project is neither passed in nor set in the environment. """ @@ -158,6 +163,7 @@ def __init__( service=None, version=None, client_info=_CLIENT_INFO, + client_options=None, _use_grpc=None, ): super(Client, self).__init__( @@ -168,6 +174,7 @@ def __init__( self.service = service if service else self.DEFAULT_SERVICE self.version = version self._client_info = client_info + self._client_options = client_options if _use_grpc is None: self._use_grpc = _USE_GRPC @@ -195,7 +202,11 @@ def report_errors_api(self): self._report_errors_api = make_report_error_api(self) else: self._report_errors_api = _ErrorReportingLoggingAPI( - self.project, self._credentials, self._http, self._client_info + self.project, + self._credentials, + self._http, + self._client_info, + self._client_options, ) return self._report_errors_api diff --git a/error_reporting/tests/unit/test__gapic.py b/error_reporting/tests/unit/test__gapic.py index 836f46b82495..00940f466df0 100644 --- a/error_reporting/tests/unit/test__gapic.py +++ b/error_reporting/tests/unit/test__gapic.py @@ -25,7 +25,9 @@ def _call_fut(client): return make_report_error_api(client) def test_make_report_error_api(self): - client = mock.Mock(spec=["project", "_credentials", "_client_info"]) + client = mock.Mock( + spec=["project", "_credentials", "_client_info", "_client_options"] + ) # Call the function being tested. patch = mock.patch( @@ -41,7 +43,9 @@ def test_make_report_error_api(self): self.assertIs(report_error_client._project, client.project) self.assertIs(report_error_client._gapic_api, patched.return_value) patched.assert_called_once_with( - credentials=client._credentials, client_info=client._client_info + credentials=client._credentials, + client_info=client._client_info, + client_options=client._client_options, ) diff --git a/error_reporting/tests/unit/test__logging.py b/error_reporting/tests/unit/test__logging.py index e2b0638b986e..726eaabfec75 100644 --- a/error_reporting/tests/unit/test__logging.py +++ b/error_reporting/tests/unit/test__logging.py @@ -40,7 +40,7 @@ def test_ctor_defaults(self, mocked_cls): self.assertIs(logging_api.logging_client, mocked_cls.return_value) mocked_cls.assert_called_once_with( - self.PROJECT, credentials, _http=None, client_info=None + self.PROJECT, credentials, _http=None, client_info=None, client_options=None ) @mock.patch("google.cloud.logging.client.Client") @@ -48,14 +48,23 @@ def test_ctor_explicit(self, mocked_cls): credentials = _make_credentials() http = mock.Mock() client_info = mock.Mock() + client_options = mock.Mock() logging_api = self._make_one( - self.PROJECT, credentials, _http=http, client_info=client_info + self.PROJECT, + credentials, + _http=http, + client_info=client_info, + client_options=client_options, ) self.assertIs(logging_api.logging_client, mocked_cls.return_value) mocked_cls.assert_called_once_with( - self.PROJECT, credentials, _http=http, client_info=client_info + self.PROJECT, + credentials, + _http=http, + client_info=client_info, + client_options=client_options, ) @mock.patch("google.cloud.logging.client.Client") diff --git a/error_reporting/tests/unit/test_client.py b/error_reporting/tests/unit/test_client.py index 5e4dc925a65f..3a7290e8aa96 100644 --- a/error_reporting/tests/unit/test_client.py +++ b/error_reporting/tests/unit/test_client.py @@ -67,16 +67,19 @@ def test_ctor_defaults(self, default_mock): def test_ctor_explicit(self): credentials = _make_credentials() client_info = mock.Mock() + client_options = mock.Mock() client = self._make_one( project=self.PROJECT, credentials=credentials, service=self.SERVICE, version=self.VERSION, client_info=client_info, + client_options=client_options, ) self.assertEqual(client.service, self.SERVICE) self.assertEqual(client.version, self.VERSION) self.assertIs(client._client_info, client_info) + self.assertIs(client._client_options, client_options) def test_report_errors_api_already(self): credentials = _make_credentials() @@ -87,11 +90,13 @@ def test_report_errors_api_already(self): def test_report_errors_api_wo_grpc(self): credentials = _make_credentials() client_info = mock.Mock() + client_options = mock.Mock() http = mock.Mock() client = self._make_one( project=self.PROJECT, credentials=credentials, client_info=client_info, + client_options=client_options, _http=http, _use_grpc=False, ) @@ -103,7 +108,9 @@ def test_report_errors_api_wo_grpc(self): api = client.report_errors_api self.assertIs(api, patched.return_value) - patched.assert_called_once_with(self.PROJECT, credentials, http, client_info) + patched.assert_called_once_with( + self.PROJECT, credentials, http, client_info, client_options + ) def test_report_errors_api_w_grpc(self): credentials = _make_credentials()