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.2, created at 2023-03-26 06:25 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:25 +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_timeout=None,
136 client_info=client_info,
137 ),
138 self.get_schema: gapic_v1.method.wrap_method(
139 self.get_schema,
140 default_timeout=None,
141 client_info=client_info,
142 ),
143 self.list_schemas: gapic_v1.method.wrap_method(
144 self.list_schemas,
145 default_timeout=None,
146 client_info=client_info,
147 ),
148 self.list_schema_revisions: gapic_v1.method.wrap_method(
149 self.list_schema_revisions,
150 default_timeout=None,
151 client_info=client_info,
152 ),
153 self.commit_schema: gapic_v1.method.wrap_method(
154 self.commit_schema,
155 default_timeout=None,
156 client_info=client_info,
157 ),
158 self.rollback_schema: gapic_v1.method.wrap_method(
159 self.rollback_schema,
160 default_timeout=None,
161 client_info=client_info,
162 ),
163 self.delete_schema_revision: gapic_v1.method.wrap_method(
164 self.delete_schema_revision,
165 default_timeout=None,
166 client_info=client_info,
167 ),
168 self.delete_schema: gapic_v1.method.wrap_method(
169 self.delete_schema,
170 default_timeout=None,
171 client_info=client_info,
172 ),
173 self.validate_schema: gapic_v1.method.wrap_method(
174 self.validate_schema,
175 default_timeout=None,
176 client_info=client_info,
177 ),
178 self.validate_message: gapic_v1.method.wrap_method(
179 self.validate_message,
180 default_timeout=None,
181 client_info=client_info,
182 ),
183 }
185 def close(self):
186 """Closes resources associated with the transport.
188 .. warning::
189 Only call this method if the transport is NOT shared
190 with other clients - this may cause errors in other clients!
191 """
192 raise NotImplementedError()
194 @property
195 def create_schema(
196 self,
197 ) -> Callable[
198 [gp_schema.CreateSchemaRequest],
199 Union[gp_schema.Schema, Awaitable[gp_schema.Schema]],
200 ]:
201 raise NotImplementedError()
203 @property
204 def get_schema(
205 self,
206 ) -> Callable[
207 [schema.GetSchemaRequest], Union[schema.Schema, Awaitable[schema.Schema]]
208 ]:
209 raise NotImplementedError()
211 @property
212 def list_schemas(
213 self,
214 ) -> Callable[
215 [schema.ListSchemasRequest],
216 Union[schema.ListSchemasResponse, Awaitable[schema.ListSchemasResponse]],
217 ]:
218 raise NotImplementedError()
220 @property
221 def list_schema_revisions(
222 self,
223 ) -> Callable[
224 [schema.ListSchemaRevisionsRequest],
225 Union[
226 schema.ListSchemaRevisionsResponse,
227 Awaitable[schema.ListSchemaRevisionsResponse],
228 ],
229 ]:
230 raise NotImplementedError()
232 @property
233 def commit_schema(
234 self,
235 ) -> Callable[
236 [gp_schema.CommitSchemaRequest],
237 Union[gp_schema.Schema, Awaitable[gp_schema.Schema]],
238 ]:
239 raise NotImplementedError()
241 @property
242 def rollback_schema(
243 self,
244 ) -> Callable[
245 [schema.RollbackSchemaRequest], Union[schema.Schema, Awaitable[schema.Schema]]
246 ]:
247 raise NotImplementedError()
249 @property
250 def delete_schema_revision(
251 self,
252 ) -> Callable[
253 [schema.DeleteSchemaRevisionRequest],
254 Union[schema.Schema, Awaitable[schema.Schema]],
255 ]:
256 raise NotImplementedError()
258 @property
259 def delete_schema(
260 self,
261 ) -> Callable[
262 [schema.DeleteSchemaRequest], Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]]
263 ]:
264 raise NotImplementedError()
266 @property
267 def validate_schema(
268 self,
269 ) -> Callable[
270 [gp_schema.ValidateSchemaRequest],
271 Union[
272 gp_schema.ValidateSchemaResponse,
273 Awaitable[gp_schema.ValidateSchemaResponse],
274 ],
275 ]:
276 raise NotImplementedError()
278 @property
279 def validate_message(
280 self,
281 ) -> Callable[
282 [schema.ValidateMessageRequest],
283 Union[
284 schema.ValidateMessageResponse, Awaitable[schema.ValidateMessageResponse]
285 ],
286 ]:
287 raise NotImplementedError()
289 @property
290 def set_iam_policy(
291 self,
292 ) -> Callable[
293 [iam_policy_pb2.SetIamPolicyRequest],
294 Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]],
295 ]:
296 raise NotImplementedError()
298 @property
299 def get_iam_policy(
300 self,
301 ) -> Callable[
302 [iam_policy_pb2.GetIamPolicyRequest],
303 Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]],
304 ]:
305 raise NotImplementedError()
307 @property
308 def test_iam_permissions(
309 self,
310 ) -> Callable[
311 [iam_policy_pb2.TestIamPermissionsRequest],
312 Union[
313 iam_policy_pb2.TestIamPermissionsResponse,
314 Awaitable[iam_policy_pb2.TestIamPermissionsResponse],
315 ],
316 ]:
317 raise NotImplementedError()
319 @property
320 def kind(self) -> str:
321 raise NotImplementedError()
324__all__ = ("SchemaServiceTransport",)