Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/pubsub_v1/services/schema_service/transports/base.py: 61%
83 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:03 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:03 +0000
1# -*- coding: utf-8 -*-
2# Copyright 2022 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import abc
17from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
19from google.pubsub_v1 import gapic_version as package_version
21import google.auth # type: ignore
22import google.api_core
23from google.api_core import exceptions as core_exceptions
24from google.api_core import gapic_v1
25from google.api_core import retry as retries
26from google.auth import credentials as ga_credentials # type: ignore
27from google.oauth2 import service_account # type: ignore
29from google.iam.v1 import iam_policy_pb2 # type: ignore
30from google.iam.v1 import policy_pb2 # type: ignore
31from google.protobuf import empty_pb2 # type: ignore
32from google.pubsub_v1.types import schema
33from google.pubsub_v1.types import schema as gp_schema
35DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
36 client_library_version=package_version.__version__
37)
40class SchemaServiceTransport(abc.ABC):
41 """Abstract transport class for SchemaService."""
43 AUTH_SCOPES = (
44 "https://www.googleapis.com/auth/cloud-platform",
45 "https://www.googleapis.com/auth/pubsub",
46 )
48 DEFAULT_HOST: str = "pubsub.googleapis.com"
50 def __init__(
51 self,
52 *,
53 host: str = DEFAULT_HOST,
54 credentials: Optional[ga_credentials.Credentials] = None,
55 credentials_file: Optional[str] = None,
56 scopes: Optional[Sequence[str]] = None,
57 quota_project_id: Optional[str] = None,
58 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
59 always_use_jwt_access: Optional[bool] = False,
60 api_audience: Optional[str] = None,
61 **kwargs,
62 ) -> None:
63 """Instantiate the transport.
65 Args:
66 host (Optional[str]):
67 The hostname to connect to.
68 credentials (Optional[google.auth.credentials.Credentials]): The
69 authorization credentials to attach to requests. These
70 credentials identify the application to the service; if none
71 are specified, the client will attempt to ascertain the
72 credentials from the environment.
73 credentials_file (Optional[str]): A file with credentials that can
74 be loaded with :func:`google.auth.load_credentials_from_file`.
75 This argument is mutually exclusive with credentials.
76 scopes (Optional[Sequence[str]]): A list of scopes.
77 quota_project_id (Optional[str]): An optional project to use for billing
78 and quota.
79 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
80 The client info used to send a user-agent string along with
81 API requests. If ``None``, then default info will be used.
82 Generally, you only need to set this if you're developing
83 your own client library.
84 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
85 be used for service account credentials.
86 """
88 scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}
90 # Save the scopes.
91 self._scopes = scopes
93 # If no credentials are provided, then determine the appropriate
94 # defaults.
95 if credentials and credentials_file:
96 raise core_exceptions.DuplicateCredentialArgs(
97 "'credentials_file' and 'credentials' are mutually exclusive"
98 )
100 if credentials_file is not None:
101 credentials, _ = google.auth.load_credentials_from_file(
102 credentials_file, **scopes_kwargs, quota_project_id=quota_project_id
103 )
104 elif credentials is None:
105 credentials, _ = google.auth.default(
106 **scopes_kwargs, quota_project_id=quota_project_id
107 )
108 # Don't apply audience if the credentials file passed from user.
109 if hasattr(credentials, "with_gdch_audience"):
110 credentials = credentials.with_gdch_audience(
111 api_audience if api_audience else host
112 )
114 # If the credentials are service account credentials, then always try to use self signed JWT.
115 if (
116 always_use_jwt_access
117 and isinstance(credentials, service_account.Credentials)
118 and hasattr(service_account.Credentials, "with_always_use_jwt_access")
119 ):
120 credentials = credentials.with_always_use_jwt_access(True)
122 # Save the credentials.
123 self._credentials = credentials
125 # Save the hostname. Default to port 443 (HTTPS) if none is specified.
126 if ":" not in host:
127 host += ":443"
128 self._host = host
130 def _prep_wrapped_messages(self, client_info):
131 # Precompute the wrapped methods.
132 self._wrapped_methods = {
133 self.create_schema: gapic_v1.method.wrap_method(
134 self.create_schema,
135 default_retry=retries.Retry(
136 initial=0.1,
137 maximum=60.0,
138 multiplier=1.3,
139 predicate=retries.if_exception_type(
140 core_exceptions.ServiceUnavailable,
141 ),
142 deadline=60.0,
143 ),
144 default_timeout=60.0,
145 client_info=client_info,
146 ),
147 self.get_schema: gapic_v1.method.wrap_method(
148 self.get_schema,
149 default_retry=retries.Retry(
150 initial=0.1,
151 maximum=60.0,
152 multiplier=1.3,
153 predicate=retries.if_exception_type(
154 core_exceptions.ServiceUnavailable,
155 ),
156 deadline=60.0,
157 ),
158 default_timeout=60.0,
159 client_info=client_info,
160 ),
161 self.list_schemas: gapic_v1.method.wrap_method(
162 self.list_schemas,
163 default_retry=retries.Retry(
164 initial=0.1,
165 maximum=60.0,
166 multiplier=1.3,
167 predicate=retries.if_exception_type(
168 core_exceptions.ServiceUnavailable,
169 ),
170 deadline=60.0,
171 ),
172 default_timeout=60.0,
173 client_info=client_info,
174 ),
175 self.list_schema_revisions: gapic_v1.method.wrap_method(
176 self.list_schema_revisions,
177 default_retry=retries.Retry(
178 initial=0.1,
179 maximum=60.0,
180 multiplier=1.3,
181 predicate=retries.if_exception_type(
182 core_exceptions.ServiceUnavailable,
183 ),
184 deadline=60.0,
185 ),
186 default_timeout=60.0,
187 client_info=client_info,
188 ),
189 self.commit_schema: gapic_v1.method.wrap_method(
190 self.commit_schema,
191 default_retry=retries.Retry(
192 initial=0.1,
193 maximum=60.0,
194 multiplier=1.3,
195 predicate=retries.if_exception_type(
196 core_exceptions.ServiceUnavailable,
197 ),
198 deadline=60.0,
199 ),
200 default_timeout=60.0,
201 client_info=client_info,
202 ),
203 self.rollback_schema: gapic_v1.method.wrap_method(
204 self.rollback_schema,
205 default_retry=retries.Retry(
206 initial=0.1,
207 maximum=60.0,
208 multiplier=1.3,
209 predicate=retries.if_exception_type(
210 core_exceptions.ServiceUnavailable,
211 ),
212 deadline=60.0,
213 ),
214 default_timeout=60.0,
215 client_info=client_info,
216 ),
217 self.delete_schema_revision: gapic_v1.method.wrap_method(
218 self.delete_schema_revision,
219 default_retry=retries.Retry(
220 initial=0.1,
221 maximum=60.0,
222 multiplier=1.3,
223 predicate=retries.if_exception_type(
224 core_exceptions.ServiceUnavailable,
225 ),
226 deadline=60.0,
227 ),
228 default_timeout=60.0,
229 client_info=client_info,
230 ),
231 self.delete_schema: gapic_v1.method.wrap_method(
232 self.delete_schema,
233 default_retry=retries.Retry(
234 initial=0.1,
235 maximum=60.0,
236 multiplier=1.3,
237 predicate=retries.if_exception_type(
238 core_exceptions.ServiceUnavailable,
239 ),
240 deadline=60.0,
241 ),
242 default_timeout=60.0,
243 client_info=client_info,
244 ),
245 self.validate_schema: gapic_v1.method.wrap_method(
246 self.validate_schema,
247 default_retry=retries.Retry(
248 initial=0.1,
249 maximum=60.0,
250 multiplier=1.3,
251 predicate=retries.if_exception_type(
252 core_exceptions.ServiceUnavailable,
253 ),
254 deadline=60.0,
255 ),
256 default_timeout=60.0,
257 client_info=client_info,
258 ),
259 self.validate_message: gapic_v1.method.wrap_method(
260 self.validate_message,
261 default_retry=retries.Retry(
262 initial=0.1,
263 maximum=60.0,
264 multiplier=1.3,
265 predicate=retries.if_exception_type(
266 core_exceptions.ServiceUnavailable,
267 ),
268 deadline=60.0,
269 ),
270 default_timeout=60.0,
271 client_info=client_info,
272 ),
273 }
275 def close(self):
276 """Closes resources associated with the transport.
278 .. warning::
279 Only call this method if the transport is NOT shared
280 with other clients - this may cause errors in other clients!
281 """
282 raise NotImplementedError()
284 @property
285 def create_schema(
286 self,
287 ) -> Callable[
288 [gp_schema.CreateSchemaRequest],
289 Union[gp_schema.Schema, Awaitable[gp_schema.Schema]],
290 ]:
291 raise NotImplementedError()
293 @property
294 def get_schema(
295 self,
296 ) -> Callable[
297 [schema.GetSchemaRequest], Union[schema.Schema, Awaitable[schema.Schema]]
298 ]:
299 raise NotImplementedError()
301 @property
302 def list_schemas(
303 self,
304 ) -> Callable[
305 [schema.ListSchemasRequest],
306 Union[schema.ListSchemasResponse, Awaitable[schema.ListSchemasResponse]],
307 ]:
308 raise NotImplementedError()
310 @property
311 def list_schema_revisions(
312 self,
313 ) -> Callable[
314 [schema.ListSchemaRevisionsRequest],
315 Union[
316 schema.ListSchemaRevisionsResponse,
317 Awaitable[schema.ListSchemaRevisionsResponse],
318 ],
319 ]:
320 raise NotImplementedError()
322 @property
323 def commit_schema(
324 self,
325 ) -> Callable[
326 [gp_schema.CommitSchemaRequest],
327 Union[gp_schema.Schema, Awaitable[gp_schema.Schema]],
328 ]:
329 raise NotImplementedError()
331 @property
332 def rollback_schema(
333 self,
334 ) -> Callable[
335 [schema.RollbackSchemaRequest], Union[schema.Schema, Awaitable[schema.Schema]]
336 ]:
337 raise NotImplementedError()
339 @property
340 def delete_schema_revision(
341 self,
342 ) -> Callable[
343 [schema.DeleteSchemaRevisionRequest],
344 Union[schema.Schema, Awaitable[schema.Schema]],
345 ]:
346 raise NotImplementedError()
348 @property
349 def delete_schema(
350 self,
351 ) -> Callable[
352 [schema.DeleteSchemaRequest], Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]]
353 ]:
354 raise NotImplementedError()
356 @property
357 def validate_schema(
358 self,
359 ) -> Callable[
360 [gp_schema.ValidateSchemaRequest],
361 Union[
362 gp_schema.ValidateSchemaResponse,
363 Awaitable[gp_schema.ValidateSchemaResponse],
364 ],
365 ]:
366 raise NotImplementedError()
368 @property
369 def validate_message(
370 self,
371 ) -> Callable[
372 [schema.ValidateMessageRequest],
373 Union[
374 schema.ValidateMessageResponse, Awaitable[schema.ValidateMessageResponse]
375 ],
376 ]:
377 raise NotImplementedError()
379 @property
380 def set_iam_policy(
381 self,
382 ) -> Callable[
383 [iam_policy_pb2.SetIamPolicyRequest],
384 Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]],
385 ]:
386 raise NotImplementedError()
388 @property
389 def get_iam_policy(
390 self,
391 ) -> Callable[
392 [iam_policy_pb2.GetIamPolicyRequest],
393 Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]],
394 ]:
395 raise NotImplementedError()
397 @property
398 def test_iam_permissions(
399 self,
400 ) -> Callable[
401 [iam_policy_pb2.TestIamPermissionsRequest],
402 Union[
403 iam_policy_pb2.TestIamPermissionsResponse,
404 Awaitable[iam_policy_pb2.TestIamPermissionsResponse],
405 ],
406 ]:
407 raise NotImplementedError()
409 @property
410 def kind(self) -> str:
411 raise NotImplementedError()
414__all__ = ("SchemaServiceTransport",)