google-cloud-logging 3.17.0__tar.gz → 3.17.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. {google_cloud_logging-3.17.0/google_cloud_logging.egg-info → google_cloud_logging-3.17.1}/PKG-INFO +1 -1
  2. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging/gapic_version.py +1 -1
  3. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/_http.py +15 -5
  4. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/client.py +20 -8
  5. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/gapic_version.py +1 -1
  6. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1/google_cloud_logging.egg-info}/PKG-INFO +1 -1
  7. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test__http.py +91 -0
  8. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test_client.py +126 -0
  9. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/LICENSE +0 -0
  10. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/MANIFEST.in +0 -0
  11. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/README.rst +0 -0
  12. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging/__init__.py +0 -0
  13. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging/handlers/__init__.py +0 -0
  14. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging/handlers/middleware/__init__.py +0 -0
  15. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging/handlers/transports/__init__.py +0 -0
  16. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging/py.typed +0 -0
  17. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/__init__.py +0 -0
  18. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/_compat.py +0 -0
  19. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/_gapic.py +0 -0
  20. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/_helpers.py +0 -0
  21. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/_instrumentation.py +0 -0
  22. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/entries.py +0 -0
  23. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/gapic_metadata.json +0 -0
  24. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/__init__.py +0 -0
  25. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/_helpers.py +0 -0
  26. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/_monitored_resources.py +0 -0
  27. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/app_engine.py +0 -0
  28. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/container_engine.py +0 -0
  29. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/handlers.py +0 -0
  30. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/middleware/__init__.py +0 -0
  31. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/middleware/request.py +0 -0
  32. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/structured_log.py +0 -0
  33. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/transports/__init__.py +0 -0
  34. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/transports/background_thread.py +0 -0
  35. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/transports/base.py +0 -0
  36. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/handlers/transports/sync.py +0 -0
  37. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/logger.py +0 -0
  38. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/metric.py +0 -0
  39. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/py.typed +0 -0
  40. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/resource.py +0 -0
  41. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/__init__.py +0 -0
  42. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/config_service_v2/__init__.py +0 -0
  43. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/config_service_v2/async_client.py +0 -0
  44. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/config_service_v2/client.py +0 -0
  45. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/config_service_v2/pagers.py +0 -0
  46. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/config_service_v2/transports/__init__.py +0 -0
  47. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/config_service_v2/transports/base.py +0 -0
  48. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py +0 -0
  49. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py +0 -0
  50. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/logging_service_v2/__init__.py +0 -0
  51. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/logging_service_v2/async_client.py +0 -0
  52. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/logging_service_v2/client.py +0 -0
  53. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/logging_service_v2/pagers.py +0 -0
  54. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/logging_service_v2/transports/__init__.py +0 -0
  55. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/logging_service_v2/transports/base.py +0 -0
  56. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py +0 -0
  57. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py +0 -0
  58. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/metrics_service_v2/__init__.py +0 -0
  59. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +0 -0
  60. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/metrics_service_v2/client.py +0 -0
  61. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/metrics_service_v2/pagers.py +0 -0
  62. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/metrics_service_v2/transports/__init__.py +0 -0
  63. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py +0 -0
  64. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py +0 -0
  65. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py +0 -0
  66. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/sink.py +0 -0
  67. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/types/__init__.py +0 -0
  68. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/types/log_entry.py +0 -0
  69. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/types/logging.py +0 -0
  70. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/types/logging_config.py +0 -0
  71. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google/cloud/logging_v2/types/logging_metrics.py +0 -0
  72. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google_cloud_logging.egg-info/SOURCES.txt +0 -0
  73. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google_cloud_logging.egg-info/dependency_links.txt +0 -0
  74. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google_cloud_logging.egg-info/not-zip-safe +0 -0
  75. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google_cloud_logging.egg-info/requires.txt +0 -0
  76. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/google_cloud_logging.egg-info/top_level.txt +0 -0
  77. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/setup.cfg +0 -0
  78. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/setup.py +0 -0
  79. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/__init__.py +0 -0
  80. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/system/gapic/v2/test_system_logging_service_v2_v2.py +0 -0
  81. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/system/test_system.py +0 -0
  82. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/__init__.py +0 -0
  83. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/gapic/__init__.py +0 -0
  84. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/gapic/logging_v2/__init__.py +0 -0
  85. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/gapic/logging_v2/test_compat.py +0 -0
  86. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/gapic/logging_v2/test_config_service_v2.py +0 -0
  87. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/gapic/logging_v2/test_logging_service_v2.py +0 -0
  88. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +0 -0
  89. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/__init__.py +0 -0
  90. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/middleware/test_request.py +0 -0
  91. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/test__helpers.py +0 -0
  92. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/test__monitored_resources.py +0 -0
  93. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/test_app_engine.py +0 -0
  94. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/test_container_engine.py +0 -0
  95. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/test_handlers.py +0 -0
  96. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/test_structured_log.py +0 -0
  97. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/transports/__init__.py +0 -0
  98. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/transports/test_background_thread.py +0 -0
  99. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/transports/test_base.py +0 -0
  100. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/handlers/transports/test_sync.py +0 -0
  101. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test__gapic.py +0 -0
  102. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test__helpers.py +0 -0
  103. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test__instrumentation.py +0 -0
  104. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test_entries.py +0 -0
  105. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test_logger.py +0 -0
  106. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test_logging_shim.py +0 -0
  107. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test_metric.py +0 -0
  108. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test_packaging.py +0 -0
  109. {google_cloud_logging-3.17.0 → google_cloud_logging-3.17.1}/tests/unit/test_sink.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-cloud-logging
3
- Version: 3.17.0
3
+ Version: 3.17.1
4
4
  Summary: Google Cloud Logging API client library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-logging
6
6
  Author: Google LLC
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- __version__ = "3.17.0" # {x-release-please-version}
16
+ __version__ = "3.17.1" # {x-release-please-version}
@@ -17,6 +17,7 @@
17
17
  import functools
18
18
 
19
19
  from google.api_core import page_iterator
20
+ from google.api_core.universe import determine_domain
20
21
 
21
22
  from google.cloud import _http
22
23
  from google.cloud.logging_v2 import __version__
@@ -27,20 +28,29 @@ from google.cloud.logging_v2.sink import Sink
27
28
 
28
29
  class Connection(_http.JSONConnection):
29
30
  DEFAULT_API_ENDPOINT = "https://logging.googleapis.com"
31
+ DEFAULT_API_ENDPOINT_TEMPLATE = "https://logging.{universe_domain}"
30
32
 
31
- def __init__(self, client, *, client_info=None, api_endpoint=DEFAULT_API_ENDPOINT):
33
+ def __init__(self, client, *, client_info=None, api_endpoint=None):
32
34
  """A connection to Google Cloud Logging via the JSON REST API.
33
35
 
34
36
  Args:
35
- client (google.cloud.logging_v2.cliet.Client):
37
+ client (google.cloud.logging_v2.client.Client):
36
38
  The client that owns the current connection.
37
39
  client_info (Optional[google.api_core.client_info.ClientInfo]):
38
40
  Instance used to generate user agent.
39
- client_options (Optional[google.api_core.client_options.ClientOptions]):
40
- Client options used to set user options
41
- on the client. API Endpoint should be set through client_options.
41
+ api_endpoint (Optional[str]):
42
+ The API endpoint to use. If not passed, derived from the
43
+ client's ``universe_domain`` (defaulting to
44
+ ``"https://logging.googleapis.com"``).
42
45
  """
43
46
  super(Connection, self).__init__(client, client_info)
47
+ if api_endpoint is None:
48
+ universe_domain = determine_domain(
49
+ getattr(client, "universe_domain", None), None
50
+ )
51
+ api_endpoint = self.DEFAULT_API_ENDPOINT_TEMPLATE.format(
52
+ universe_domain=universe_domain
53
+ )
44
54
  self.API_BASE_URL = api_endpoint
45
55
  self._client_info.gapic_version = __version__
46
56
  self._client_info.client_library_version = __version__
@@ -19,6 +19,7 @@ import os
19
19
  import sys
20
20
 
21
21
  import google.api_core.client_options
22
+ import google.api_core.universe
22
23
  from google.cloud.client import ClientWithProject
23
24
  from google.cloud.environment_vars import DISABLE_GRPC
24
25
 
@@ -125,15 +126,17 @@ class Client(ClientWithProject):
125
126
  client_options=client_options,
126
127
  )
127
128
 
129
+ if isinstance(client_options, dict):
130
+ client_options = google.api_core.client_options.from_dict(client_options)
131
+
132
+ self._universe_domain = google.api_core.universe.determine_domain(
133
+ getattr(client_options, "universe_domain", None),
134
+ os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN"),
135
+ )
136
+
128
137
  kw_args = {"client_info": client_info}
129
- if client_options:
130
- if isinstance(client_options, dict):
131
- client_options = google.api_core.client_options.from_dict(
132
- client_options
133
- )
134
- if client_options.api_endpoint:
135
- api_endpoint = client_options.api_endpoint
136
- kw_args["api_endpoint"] = api_endpoint
138
+ if client_options and client_options.api_endpoint:
139
+ kw_args["api_endpoint"] = client_options.api_endpoint
137
140
 
138
141
  self._connection = Connection(self, **kw_args)
139
142
  if client_info is None:
@@ -150,6 +153,15 @@ class Client(ClientWithProject):
150
153
 
151
154
  self._handlers = set()
152
155
 
156
+ @property
157
+ def universe_domain(self) -> str:
158
+ """Return the universe domain used by the client instance.
159
+
160
+ Returns:
161
+ str: The universe domain used by the client instance.
162
+ """
163
+ return self._universe_domain
164
+
153
165
  @property
154
166
  def logging_api(self):
155
167
  """Helper for logging-related API calls.
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- __version__ = "3.17.0" # {x-release-please-version}
16
+ __version__ = "3.17.1" # {x-release-please-version}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-cloud-logging
3
- Version: 3.17.0
3
+ Version: 3.17.1
4
4
  Summary: Google Cloud Logging API client library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-logging
6
6
  Author: Google LLC
@@ -46,6 +46,53 @@ class TestConnection(unittest.TestCase):
46
46
  client = object()
47
47
  conn = self._make_one(client)
48
48
  self.assertIs(conn._client, client)
49
+ self.assertEqual(conn.API_BASE_URL, conn.DEFAULT_API_ENDPOINT)
50
+
51
+ def test_none_universe_domain_falls_back_to_default(self):
52
+ client = mock.Mock(universe_domain=None, spec=["universe_domain"])
53
+ conn = self._make_one(client)
54
+ self.assertEqual(conn.API_BASE_URL, conn.DEFAULT_API_ENDPOINT)
55
+
56
+ def test_empty_universe_domain_raises(self):
57
+ from google.api_core.universe import EmptyUniverseError
58
+
59
+ client = mock.Mock(universe_domain="", spec=["universe_domain"])
60
+ with self.assertRaises(EmptyUniverseError):
61
+ self._make_one(client)
62
+
63
+ def test_universe_domain_url(self):
64
+ client = mock.Mock(universe_domain="example.com", spec=["universe_domain"])
65
+ conn = self._make_one(client)
66
+ self.assertEqual(conn.API_BASE_URL, "https://logging.example.com")
67
+ self.assertEqual(
68
+ conn.build_api_url("/entries:write"),
69
+ "https://logging.example.com/v2/entries:write?prettyPrint=false",
70
+ )
71
+
72
+ def test_custom_endpoint_overrides_universe_domain(self):
73
+ custom_endpoint = "https://custom.logging.endpoint"
74
+ client = mock.Mock(universe_domain="example.com", spec=["universe_domain"])
75
+ conn = self._make_one(client, api_endpoint=custom_endpoint)
76
+ self.assertEqual(conn.API_BASE_URL, custom_endpoint)
77
+ self.assertEqual(
78
+ conn.build_api_url("/entries:write"),
79
+ "https://custom.logging.endpoint/v2/entries:write?prettyPrint=false",
80
+ )
81
+
82
+ def test_mtls_does_not_override_custom_universe_domain(self):
83
+ http = mock.Mock(is_mtls=True, spec=["is_mtls"])
84
+ client = mock.Mock(
85
+ universe_domain="example.com",
86
+ _http=http,
87
+ spec=["universe_domain", "_http"],
88
+ )
89
+ conn = self._make_one(client)
90
+ self.assertFalse(conn.ALLOW_AUTO_SWITCH_TO_MTLS_URL)
91
+ self.assertIsNone(conn.API_BASE_MTLS_URL)
92
+ self.assertEqual(
93
+ conn.build_api_url("/entries:write"),
94
+ "https://logging.example.com/v2/entries:write?prettyPrint=false",
95
+ )
49
96
 
50
97
  def test_build_api_url_w_custom_endpoint(self):
51
98
  from urllib.parse import parse_qsl, urlsplit
@@ -350,6 +397,50 @@ class Test_LoggingAPI(unittest.TestCase):
350
397
  self.assertEqual(conn._called_with["method"], "DELETE")
351
398
  self.assertEqual(conn._called_with["path"], path)
352
399
 
400
+ def test_background_thread_transport_batch_commit_universe_domain(self):
401
+ import json
402
+ import logging
403
+ import os
404
+
405
+ import requests
406
+
407
+ from google.cloud.logging import Client
408
+ from google.cloud.logging.handlers.transports import BackgroundThreadTransport
409
+
410
+ http = mock.create_autospec(requests.Session, instance=True)
411
+ response = requests.Response()
412
+ response.status_code = 200
413
+ response._content = b"{}"
414
+ http.request.return_value = response
415
+
416
+ with mock.patch.dict(
417
+ os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "example.com"}
418
+ ):
419
+ client = Client(
420
+ project=self.PROJECT,
421
+ _http=http,
422
+ _use_grpc=False,
423
+ )
424
+
425
+ self.assertIsInstance(client.logging_api, self._get_target_class())
426
+ transport = BackgroundThreadTransport(client, self.LOGGER_NAME)
427
+ record = logging.LogRecord(
428
+ "mylogger", logging.INFO, __file__, 1, "hello world", None, None
429
+ )
430
+ transport.send(record, "hello world")
431
+ transport.flush()
432
+ transport.close()
433
+
434
+ http.request.assert_called_once()
435
+ call_kwargs = http.request.call_args.kwargs
436
+ self.assertEqual(call_kwargs["method"], "POST")
437
+ self.assertEqual(
438
+ call_kwargs["url"],
439
+ "https://logging.example.com/v2/entries:write?prettyPrint=false",
440
+ )
441
+ payload = json.loads(call_kwargs["data"])
442
+ self.assertEqual(payload["entries"][0]["textPayload"], "hello world")
443
+
353
444
 
354
445
  class Test_SinksAPI(unittest.TestCase):
355
446
  PROJECT = "project"
@@ -113,6 +113,132 @@ class TestClient(unittest.TestCase):
113
113
  client._connection.API_BASE_URL, "https://foo-logging.googleapis.com"
114
114
  )
115
115
 
116
+ def test_ctor_default_universe_domain(self):
117
+ creds = _make_credentials()
118
+ client = self._make_one(
119
+ project=self.PROJECT, credentials=creds, _use_grpc=False
120
+ )
121
+ self.assertEqual(client.universe_domain, "googleapis.com")
122
+ self.assertEqual(
123
+ client._connection.API_BASE_URL, "https://logging.googleapis.com"
124
+ )
125
+
126
+ def test_ctor_w_universe_domain_dict_http(self):
127
+ creds = _make_credentials()
128
+ client = self._make_one(
129
+ project=self.PROJECT,
130
+ credentials=creds,
131
+ client_options={"universe_domain": "example.com"},
132
+ _use_grpc=False,
133
+ )
134
+ self.assertEqual(client.universe_domain, "example.com")
135
+ self.assertEqual(client._connection.API_BASE_URL, "https://logging.example.com")
136
+
137
+ def test_ctor_w_universe_domain_client_options_object_http(self):
138
+ from google.api_core.client_options import ClientOptions
139
+
140
+ creds = _make_credentials()
141
+ client_options = ClientOptions(universe_domain="example.com")
142
+ client = self._make_one(
143
+ project=self.PROJECT,
144
+ credentials=creds,
145
+ client_options=client_options,
146
+ _use_grpc=False,
147
+ )
148
+ self.assertEqual(client.universe_domain, "example.com")
149
+ self.assertEqual(client._connection.API_BASE_URL, "https://logging.example.com")
150
+
151
+ def test_ctor_w_universe_domain_env_var_http(self):
152
+ import os
153
+
154
+ creds = _make_credentials()
155
+ with mock.patch.dict(
156
+ os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "example.com"}
157
+ ):
158
+ client = self._make_one(
159
+ project=self.PROJECT, credentials=creds, _use_grpc=False
160
+ )
161
+ self.assertEqual(client.universe_domain, "example.com")
162
+ self.assertEqual(client._connection.API_BASE_URL, "https://logging.example.com")
163
+
164
+ def test_ctor_universe_domain_precedence(self):
165
+ import os
166
+
167
+ from google.api_core.client_options import ClientOptions
168
+
169
+ creds = _make_credentials()
170
+ with mock.patch.dict(
171
+ os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "env-universe.example.com"}
172
+ ):
173
+ # client_options.universe_domain overrides GOOGLE_CLOUD_UNIVERSE_DOMAIN
174
+ client = self._make_one(
175
+ project=self.PROJECT,
176
+ credentials=creds,
177
+ client_options=ClientOptions(universe_domain="example.com"),
178
+ _use_grpc=False,
179
+ )
180
+ self.assertEqual(client.universe_domain, "example.com")
181
+ self.assertEqual(
182
+ client._connection.API_BASE_URL, "https://logging.example.com"
183
+ )
184
+
185
+ # client_options.api_endpoint overrides universe_domain and env var
186
+ client_custom_ep = self._make_one(
187
+ project=self.PROJECT,
188
+ credentials=creds,
189
+ client_options={
190
+ "api_endpoint": "https://custom-logging.example.com",
191
+ "universe_domain": "example.com",
192
+ },
193
+ _use_grpc=False,
194
+ )
195
+ self.assertEqual(client_custom_ep.universe_domain, "example.com")
196
+ self.assertEqual(
197
+ client_custom_ep._connection.API_BASE_URL,
198
+ "https://custom-logging.example.com",
199
+ )
200
+
201
+ # client_options.api_endpoint also overrides GOOGLE_CLOUD_UNIVERSE_DOMAIN alone
202
+ with mock.patch.dict(
203
+ os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "example.com"}
204
+ ):
205
+ client_ep_over_env = self._make_one(
206
+ project=self.PROJECT,
207
+ credentials=creds,
208
+ client_options={"api_endpoint": "https://custom-logging.example.com"},
209
+ _use_grpc=False,
210
+ )
211
+ self.assertEqual(client_ep_over_env.universe_domain, "example.com")
212
+ self.assertEqual(
213
+ client_ep_over_env._connection.API_BASE_URL,
214
+ "https://custom-logging.example.com",
215
+ )
216
+
217
+ def test_ctor_empty_universe_domain_raises(self):
218
+ import os
219
+
220
+ from google.api_core.client_options import ClientOptions
221
+ from google.api_core.universe import EmptyUniverseError
222
+
223
+ creds = _make_credentials()
224
+ with self.assertRaises(EmptyUniverseError):
225
+ self._make_one(
226
+ project=self.PROJECT,
227
+ credentials=creds,
228
+ client_options={"universe_domain": ""},
229
+ )
230
+
231
+ with self.assertRaises(EmptyUniverseError):
232
+ self._make_one(
233
+ project=self.PROJECT,
234
+ credentials=creds,
235
+ client_options=ClientOptions(universe_domain=""),
236
+ )
237
+
238
+ with mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": ""}):
239
+ with self.assertRaises(EmptyUniverseError):
240
+ self._make_one(project=self.PROJECT, credentials=creds)
241
+
116
242
  def test_logging_api_wo_gapic(self):
117
243
  from google.cloud.logging_v2._http import _LoggingAPI
118
244