Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/pubsub_v1/services/schema_service/transports/grpc_asyncio.py: 47%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

143 statements  

1# -*- coding: utf-8 -*- 

2# Copyright 2025 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 inspect 

17import json 

18import pickle 

19import logging as std_logging 

20import warnings 

21from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union 

22 

23from google.api_core import gapic_v1 

24from google.api_core import grpc_helpers_async 

25from google.api_core import exceptions as core_exceptions 

26from google.api_core import retry_async as retries 

27from google.auth import credentials as ga_credentials # type: ignore 

28from google.auth.transport.grpc import SslCredentials # type: ignore 

29from google.protobuf.json_format import MessageToJson 

30import google.protobuf.message 

31 

32import grpc # type: ignore 

33import proto # type: ignore 

34from grpc.experimental import aio # type: ignore 

35 

36from google.iam.v1 import iam_policy_pb2 # type: ignore 

37from google.iam.v1 import policy_pb2 # type: ignore 

38from google.protobuf import empty_pb2 # type: ignore 

39from google.pubsub_v1.types import schema 

40from google.pubsub_v1.types import schema as gp_schema 

41from .base import SchemaServiceTransport, DEFAULT_CLIENT_INFO 

42from .grpc import SchemaServiceGrpcTransport 

43 

44try: 

45 from google.api_core import client_logging # type: ignore 

46 

47 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

48except ImportError: # pragma: NO COVER 

49 CLIENT_LOGGING_SUPPORTED = False 

50 

51_LOGGER = std_logging.getLogger(__name__) 

52 

53 

54class _LoggingClientAIOInterceptor( 

55 grpc.aio.UnaryUnaryClientInterceptor 

56): # pragma: NO COVER 

57 async def intercept_unary_unary(self, continuation, client_call_details, request): 

58 logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

59 std_logging.DEBUG 

60 ) 

61 if logging_enabled: # pragma: NO COVER 

62 request_metadata = client_call_details.metadata 

63 if isinstance(request, proto.Message): 

64 request_payload = type(request).to_json(request) 

65 elif isinstance(request, google.protobuf.message.Message): 

66 request_payload = MessageToJson(request) 

67 else: 

68 request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" 

69 

70 request_metadata = { 

71 key: value.decode("utf-8") if isinstance(value, bytes) else value 

72 for key, value in request_metadata 

73 } 

74 grpc_request = { 

75 "payload": request_payload, 

76 "requestMethod": "grpc", 

77 "metadata": dict(request_metadata), 

78 } 

79 _LOGGER.debug( 

80 f"Sending request for {client_call_details.method}", 

81 extra={ 

82 "serviceName": "google.pubsub.v1.SchemaService", 

83 "rpcName": str(client_call_details.method), 

84 "request": grpc_request, 

85 "metadata": grpc_request["metadata"], 

86 }, 

87 ) 

88 response = await continuation(client_call_details, request) 

89 if logging_enabled: # pragma: NO COVER 

90 response_metadata = await response.trailing_metadata() 

91 # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples 

92 metadata = ( 

93 dict([(k, str(v)) for k, v in response_metadata]) 

94 if response_metadata 

95 else None 

96 ) 

97 result = await response 

98 if isinstance(result, proto.Message): 

99 response_payload = type(result).to_json(result) 

100 elif isinstance(result, google.protobuf.message.Message): 

101 response_payload = MessageToJson(result) 

102 else: 

103 response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" 

104 grpc_response = { 

105 "payload": response_payload, 

106 "metadata": metadata, 

107 "status": "OK", 

108 } 

109 _LOGGER.debug( 

110 f"Received response to rpc {client_call_details.method}.", 

111 extra={ 

112 "serviceName": "google.pubsub.v1.SchemaService", 

113 "rpcName": str(client_call_details.method), 

114 "response": grpc_response, 

115 "metadata": grpc_response["metadata"], 

116 }, 

117 ) 

118 return response 

119 

120 

121class SchemaServiceGrpcAsyncIOTransport(SchemaServiceTransport): 

122 """gRPC AsyncIO backend transport for SchemaService. 

123 

124 Service for doing schema-related operations. 

125 

126 This class defines the same methods as the primary client, so the 

127 primary client can load the underlying transport implementation 

128 and call it. 

129 

130 It sends protocol buffers over the wire using gRPC (which is built on 

131 top of HTTP/2); the ``grpcio`` package must be installed. 

132 """ 

133 

134 _grpc_channel: aio.Channel 

135 _stubs: Dict[str, Callable] = {} 

136 

137 @classmethod 

138 def create_channel( 

139 cls, 

140 host: str = "pubsub.googleapis.com", 

141 credentials: Optional[ga_credentials.Credentials] = None, 

142 credentials_file: Optional[str] = None, 

143 scopes: Optional[Sequence[str]] = None, 

144 quota_project_id: Optional[str] = None, 

145 **kwargs, 

146 ) -> aio.Channel: 

147 """Create and return a gRPC AsyncIO channel object. 

148 Args: 

149 host (Optional[str]): The host for the channel to use. 

150 credentials (Optional[~.Credentials]): The 

151 authorization credentials to attach to requests. These 

152 credentials identify this application to the service. If 

153 none are specified, the client will attempt to ascertain 

154 the credentials from the environment. 

155 credentials_file (Optional[str]): Deprecated. A file with credentials that can 

156 be loaded with :func:`google.auth.load_credentials_from_file`. This argument will be 

157 removed in the next major version of this library. 

158 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this 

159 service. These are only used when credentials are not specified and 

160 are passed to :func:`google.auth.default`. 

161 quota_project_id (Optional[str]): An optional project to use for billing 

162 and quota. 

163 kwargs (Optional[dict]): Keyword arguments, which are passed to the 

164 channel creation. 

165 Returns: 

166 aio.Channel: A gRPC AsyncIO channel object. 

167 """ 

168 

169 return grpc_helpers_async.create_channel( 

170 host, 

171 credentials=credentials, 

172 credentials_file=credentials_file, 

173 quota_project_id=quota_project_id, 

174 default_scopes=cls.AUTH_SCOPES, 

175 scopes=scopes, 

176 default_host=cls.DEFAULT_HOST, 

177 **kwargs, 

178 ) 

179 

180 def __init__( 

181 self, 

182 *, 

183 host: str = "pubsub.googleapis.com", 

184 credentials: Optional[ga_credentials.Credentials] = None, 

185 credentials_file: Optional[str] = None, 

186 scopes: Optional[Sequence[str]] = None, 

187 channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None, 

188 api_mtls_endpoint: Optional[str] = None, 

189 client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

190 ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None, 

191 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, 

192 quota_project_id: Optional[str] = None, 

193 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

194 always_use_jwt_access: Optional[bool] = False, 

195 api_audience: Optional[str] = None, 

196 ) -> None: 

197 """Instantiate the transport. 

198 

199 Args: 

200 host (Optional[str]): 

201 The hostname to connect to (default: 'pubsub.googleapis.com'). 

202 credentials (Optional[google.auth.credentials.Credentials]): The 

203 authorization credentials to attach to requests. These 

204 credentials identify the application to the service; if none 

205 are specified, the client will attempt to ascertain the 

206 credentials from the environment. 

207 This argument is ignored if a ``channel`` instance is provided. 

208 credentials_file (Optional[str]): Deprecated. A file with credentials that can 

209 be loaded with :func:`google.auth.load_credentials_from_file`. 

210 This argument is ignored if a ``channel`` instance is provided. 

211 This argument will be removed in the next major version of this library. 

212 scopes (Optional[Sequence[str]]): A optional list of scopes needed for this 

213 service. These are only used when credentials are not specified and 

214 are passed to :func:`google.auth.default`. 

215 channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]): 

216 A ``Channel`` instance through which to make calls, or a Callable 

217 that constructs and returns one. If set to None, ``self.create_channel`` 

218 is used to create the channel. If a Callable is given, it will be called 

219 with the same arguments as used in ``self.create_channel``. 

220 api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. 

221 If provided, it overrides the ``host`` argument and tries to create 

222 a mutual TLS channel with client SSL credentials from 

223 ``client_cert_source`` or application default SSL credentials. 

224 client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): 

225 Deprecated. A callback to provide client SSL certificate bytes and 

226 private key bytes, both in PEM format. It is ignored if 

227 ``api_mtls_endpoint`` is None. 

228 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials 

229 for the grpc channel. It is ignored if a ``channel`` instance is provided. 

230 client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): 

231 A callback to provide client certificate bytes and private key bytes, 

232 both in PEM format. It is used to configure a mutual TLS channel. It is 

233 ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided. 

234 quota_project_id (Optional[str]): An optional project to use for billing 

235 and quota. 

236 client_info (google.api_core.gapic_v1.client_info.ClientInfo): 

237 The client info used to send a user-agent string along with 

238 API requests. If ``None``, then default info will be used. 

239 Generally, you only need to set this if you're developing 

240 your own client library. 

241 always_use_jwt_access (Optional[bool]): Whether self signed JWT should 

242 be used for service account credentials. 

243 

244 Raises: 

245 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport 

246 creation failed for any reason. 

247 google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` 

248 and ``credentials_file`` are passed. 

249 """ 

250 self._grpc_channel = None 

251 self._ssl_channel_credentials = ssl_channel_credentials 

252 self._stubs: Dict[str, Callable] = {} 

253 

254 if api_mtls_endpoint: 

255 warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) 

256 if client_cert_source: 

257 warnings.warn("client_cert_source is deprecated", DeprecationWarning) 

258 

259 if isinstance(channel, aio.Channel): 

260 # Ignore credentials if a channel was passed. 

261 credentials = None 

262 self._ignore_credentials = True 

263 # If a channel was explicitly provided, set it. 

264 self._grpc_channel = channel 

265 self._ssl_channel_credentials = None 

266 else: 

267 if api_mtls_endpoint: 

268 host = api_mtls_endpoint 

269 

270 # Create SSL credentials with client_cert_source or application 

271 # default SSL credentials. 

272 if client_cert_source: 

273 cert, key = client_cert_source() 

274 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

275 certificate_chain=cert, private_key=key 

276 ) 

277 else: 

278 self._ssl_channel_credentials = SslCredentials().ssl_credentials 

279 

280 else: 

281 if client_cert_source_for_mtls and not ssl_channel_credentials: 

282 cert, key = client_cert_source_for_mtls() 

283 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

284 certificate_chain=cert, private_key=key 

285 ) 

286 

287 # The base transport sets the host, credentials and scopes 

288 super().__init__( 

289 host=host, 

290 credentials=credentials, 

291 credentials_file=credentials_file, 

292 scopes=scopes, 

293 quota_project_id=quota_project_id, 

294 client_info=client_info, 

295 always_use_jwt_access=always_use_jwt_access, 

296 api_audience=api_audience, 

297 ) 

298 

299 if not self._grpc_channel: 

300 # initialize with the provided callable or the default channel 

301 channel_init = channel or type(self).create_channel 

302 self._grpc_channel = channel_init( 

303 self._host, 

304 # use the credentials which are saved 

305 credentials=self._credentials, 

306 # Set ``credentials_file`` to ``None`` here as 

307 # the credentials that we saved earlier should be used. 

308 credentials_file=None, 

309 scopes=self._scopes, 

310 ssl_credentials=self._ssl_channel_credentials, 

311 quota_project_id=quota_project_id, 

312 options=[ 

313 ("grpc.max_send_message_length", -1), 

314 ("grpc.max_receive_message_length", -1), 

315 ("grpc.max_metadata_size", 4 * 1024 * 1024), 

316 ("grpc.keepalive_time_ms", 30000), 

317 ], 

318 ) 

319 

320 self._interceptor = _LoggingClientAIOInterceptor() 

321 self._grpc_channel._unary_unary_interceptors.append(self._interceptor) 

322 self._logged_channel = self._grpc_channel 

323 self._wrap_with_kind = ( 

324 "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters 

325 ) 

326 # Wrap messages. This must be done after self._logged_channel exists 

327 self._prep_wrapped_messages(client_info) 

328 

329 @property 

330 def grpc_channel(self) -> aio.Channel: 

331 """Create the channel designed to connect to this service. 

332 

333 This property caches on the instance; repeated calls return 

334 the same channel. 

335 """ 

336 # Return the channel from cache. 

337 return self._grpc_channel 

338 

339 @property 

340 def create_schema( 

341 self, 

342 ) -> Callable[[gp_schema.CreateSchemaRequest], Awaitable[gp_schema.Schema]]: 

343 r"""Return a callable for the create schema method over gRPC. 

344 

345 Creates a schema. 

346 

347 Returns: 

348 Callable[[~.CreateSchemaRequest], 

349 Awaitable[~.Schema]]: 

350 A function that, when called, will call the underlying RPC 

351 on the server. 

352 """ 

353 # Generate a "stub function" on-the-fly which will actually make 

354 # the request. 

355 # gRPC handles serialization and deserialization, so we just need 

356 # to pass in the functions for each. 

357 if "create_schema" not in self._stubs: 

358 self._stubs["create_schema"] = self._logged_channel.unary_unary( 

359 "/google.pubsub.v1.SchemaService/CreateSchema", 

360 request_serializer=gp_schema.CreateSchemaRequest.serialize, 

361 response_deserializer=gp_schema.Schema.deserialize, 

362 ) 

363 return self._stubs["create_schema"] 

364 

365 @property 

366 def get_schema( 

367 self, 

368 ) -> Callable[[schema.GetSchemaRequest], Awaitable[schema.Schema]]: 

369 r"""Return a callable for the get schema method over gRPC. 

370 

371 Gets a schema. 

372 

373 Returns: 

374 Callable[[~.GetSchemaRequest], 

375 Awaitable[~.Schema]]: 

376 A function that, when called, will call the underlying RPC 

377 on the server. 

378 """ 

379 # Generate a "stub function" on-the-fly which will actually make 

380 # the request. 

381 # gRPC handles serialization and deserialization, so we just need 

382 # to pass in the functions for each. 

383 if "get_schema" not in self._stubs: 

384 self._stubs["get_schema"] = self._logged_channel.unary_unary( 

385 "/google.pubsub.v1.SchemaService/GetSchema", 

386 request_serializer=schema.GetSchemaRequest.serialize, 

387 response_deserializer=schema.Schema.deserialize, 

388 ) 

389 return self._stubs["get_schema"] 

390 

391 @property 

392 def list_schemas( 

393 self, 

394 ) -> Callable[[schema.ListSchemasRequest], Awaitable[schema.ListSchemasResponse]]: 

395 r"""Return a callable for the list schemas method over gRPC. 

396 

397 Lists schemas in a project. 

398 

399 Returns: 

400 Callable[[~.ListSchemasRequest], 

401 Awaitable[~.ListSchemasResponse]]: 

402 A function that, when called, will call the underlying RPC 

403 on the server. 

404 """ 

405 # Generate a "stub function" on-the-fly which will actually make 

406 # the request. 

407 # gRPC handles serialization and deserialization, so we just need 

408 # to pass in the functions for each. 

409 if "list_schemas" not in self._stubs: 

410 self._stubs["list_schemas"] = self._logged_channel.unary_unary( 

411 "/google.pubsub.v1.SchemaService/ListSchemas", 

412 request_serializer=schema.ListSchemasRequest.serialize, 

413 response_deserializer=schema.ListSchemasResponse.deserialize, 

414 ) 

415 return self._stubs["list_schemas"] 

416 

417 @property 

418 def list_schema_revisions( 

419 self, 

420 ) -> Callable[ 

421 [schema.ListSchemaRevisionsRequest], 

422 Awaitable[schema.ListSchemaRevisionsResponse], 

423 ]: 

424 r"""Return a callable for the list schema revisions method over gRPC. 

425 

426 Lists all schema revisions for the named schema. 

427 

428 Returns: 

429 Callable[[~.ListSchemaRevisionsRequest], 

430 Awaitable[~.ListSchemaRevisionsResponse]]: 

431 A function that, when called, will call the underlying RPC 

432 on the server. 

433 """ 

434 # Generate a "stub function" on-the-fly which will actually make 

435 # the request. 

436 # gRPC handles serialization and deserialization, so we just need 

437 # to pass in the functions for each. 

438 if "list_schema_revisions" not in self._stubs: 

439 self._stubs["list_schema_revisions"] = self._logged_channel.unary_unary( 

440 "/google.pubsub.v1.SchemaService/ListSchemaRevisions", 

441 request_serializer=schema.ListSchemaRevisionsRequest.serialize, 

442 response_deserializer=schema.ListSchemaRevisionsResponse.deserialize, 

443 ) 

444 return self._stubs["list_schema_revisions"] 

445 

446 @property 

447 def commit_schema( 

448 self, 

449 ) -> Callable[[gp_schema.CommitSchemaRequest], Awaitable[gp_schema.Schema]]: 

450 r"""Return a callable for the commit schema method over gRPC. 

451 

452 Commits a new schema revision to an existing schema. 

453 

454 Returns: 

455 Callable[[~.CommitSchemaRequest], 

456 Awaitable[~.Schema]]: 

457 A function that, when called, will call the underlying RPC 

458 on the server. 

459 """ 

460 # Generate a "stub function" on-the-fly which will actually make 

461 # the request. 

462 # gRPC handles serialization and deserialization, so we just need 

463 # to pass in the functions for each. 

464 if "commit_schema" not in self._stubs: 

465 self._stubs["commit_schema"] = self._logged_channel.unary_unary( 

466 "/google.pubsub.v1.SchemaService/CommitSchema", 

467 request_serializer=gp_schema.CommitSchemaRequest.serialize, 

468 response_deserializer=gp_schema.Schema.deserialize, 

469 ) 

470 return self._stubs["commit_schema"] 

471 

472 @property 

473 def rollback_schema( 

474 self, 

475 ) -> Callable[[schema.RollbackSchemaRequest], Awaitable[schema.Schema]]: 

476 r"""Return a callable for the rollback schema method over gRPC. 

477 

478 Creates a new schema revision that is a copy of the provided 

479 revision_id. 

480 

481 Returns: 

482 Callable[[~.RollbackSchemaRequest], 

483 Awaitable[~.Schema]]: 

484 A function that, when called, will call the underlying RPC 

485 on the server. 

486 """ 

487 # Generate a "stub function" on-the-fly which will actually make 

488 # the request. 

489 # gRPC handles serialization and deserialization, so we just need 

490 # to pass in the functions for each. 

491 if "rollback_schema" not in self._stubs: 

492 self._stubs["rollback_schema"] = self._logged_channel.unary_unary( 

493 "/google.pubsub.v1.SchemaService/RollbackSchema", 

494 request_serializer=schema.RollbackSchemaRequest.serialize, 

495 response_deserializer=schema.Schema.deserialize, 

496 ) 

497 return self._stubs["rollback_schema"] 

498 

499 @property 

500 def delete_schema_revision( 

501 self, 

502 ) -> Callable[[schema.DeleteSchemaRevisionRequest], Awaitable[schema.Schema]]: 

503 r"""Return a callable for the delete schema revision method over gRPC. 

504 

505 Deletes a specific schema revision. 

506 

507 Returns: 

508 Callable[[~.DeleteSchemaRevisionRequest], 

509 Awaitable[~.Schema]]: 

510 A function that, when called, will call the underlying RPC 

511 on the server. 

512 """ 

513 # Generate a "stub function" on-the-fly which will actually make 

514 # the request. 

515 # gRPC handles serialization and deserialization, so we just need 

516 # to pass in the functions for each. 

517 if "delete_schema_revision" not in self._stubs: 

518 self._stubs["delete_schema_revision"] = self._logged_channel.unary_unary( 

519 "/google.pubsub.v1.SchemaService/DeleteSchemaRevision", 

520 request_serializer=schema.DeleteSchemaRevisionRequest.serialize, 

521 response_deserializer=schema.Schema.deserialize, 

522 ) 

523 return self._stubs["delete_schema_revision"] 

524 

525 @property 

526 def delete_schema( 

527 self, 

528 ) -> Callable[[schema.DeleteSchemaRequest], Awaitable[empty_pb2.Empty]]: 

529 r"""Return a callable for the delete schema method over gRPC. 

530 

531 Deletes a schema. 

532 

533 Returns: 

534 Callable[[~.DeleteSchemaRequest], 

535 Awaitable[~.Empty]]: 

536 A function that, when called, will call the underlying RPC 

537 on the server. 

538 """ 

539 # Generate a "stub function" on-the-fly which will actually make 

540 # the request. 

541 # gRPC handles serialization and deserialization, so we just need 

542 # to pass in the functions for each. 

543 if "delete_schema" not in self._stubs: 

544 self._stubs["delete_schema"] = self._logged_channel.unary_unary( 

545 "/google.pubsub.v1.SchemaService/DeleteSchema", 

546 request_serializer=schema.DeleteSchemaRequest.serialize, 

547 response_deserializer=empty_pb2.Empty.FromString, 

548 ) 

549 return self._stubs["delete_schema"] 

550 

551 @property 

552 def validate_schema( 

553 self, 

554 ) -> Callable[ 

555 [gp_schema.ValidateSchemaRequest], Awaitable[gp_schema.ValidateSchemaResponse] 

556 ]: 

557 r"""Return a callable for the validate schema method over gRPC. 

558 

559 Validates a schema. 

560 

561 Returns: 

562 Callable[[~.ValidateSchemaRequest], 

563 Awaitable[~.ValidateSchemaResponse]]: 

564 A function that, when called, will call the underlying RPC 

565 on the server. 

566 """ 

567 # Generate a "stub function" on-the-fly which will actually make 

568 # the request. 

569 # gRPC handles serialization and deserialization, so we just need 

570 # to pass in the functions for each. 

571 if "validate_schema" not in self._stubs: 

572 self._stubs["validate_schema"] = self._logged_channel.unary_unary( 

573 "/google.pubsub.v1.SchemaService/ValidateSchema", 

574 request_serializer=gp_schema.ValidateSchemaRequest.serialize, 

575 response_deserializer=gp_schema.ValidateSchemaResponse.deserialize, 

576 ) 

577 return self._stubs["validate_schema"] 

578 

579 @property 

580 def validate_message( 

581 self, 

582 ) -> Callable[ 

583 [schema.ValidateMessageRequest], Awaitable[schema.ValidateMessageResponse] 

584 ]: 

585 r"""Return a callable for the validate message method over gRPC. 

586 

587 Validates a message against a schema. 

588 

589 Returns: 

590 Callable[[~.ValidateMessageRequest], 

591 Awaitable[~.ValidateMessageResponse]]: 

592 A function that, when called, will call the underlying RPC 

593 on the server. 

594 """ 

595 # Generate a "stub function" on-the-fly which will actually make 

596 # the request. 

597 # gRPC handles serialization and deserialization, so we just need 

598 # to pass in the functions for each. 

599 if "validate_message" not in self._stubs: 

600 self._stubs["validate_message"] = self._logged_channel.unary_unary( 

601 "/google.pubsub.v1.SchemaService/ValidateMessage", 

602 request_serializer=schema.ValidateMessageRequest.serialize, 

603 response_deserializer=schema.ValidateMessageResponse.deserialize, 

604 ) 

605 return self._stubs["validate_message"] 

606 

607 def _prep_wrapped_messages(self, client_info): 

608 """Precompute the wrapped methods, overriding the base class method to use async wrappers.""" 

609 self._wrapped_methods = { 

610 self.create_schema: self._wrap_method( 

611 self.create_schema, 

612 default_retry=retries.AsyncRetry( 

613 initial=0.1, 

614 maximum=60.0, 

615 multiplier=1.3, 

616 predicate=retries.if_exception_type( 

617 core_exceptions.ServiceUnavailable, 

618 ), 

619 deadline=60.0, 

620 ), 

621 default_timeout=60.0, 

622 client_info=client_info, 

623 ), 

624 self.get_schema: self._wrap_method( 

625 self.get_schema, 

626 default_retry=retries.AsyncRetry( 

627 initial=0.1, 

628 maximum=60.0, 

629 multiplier=1.3, 

630 predicate=retries.if_exception_type( 

631 core_exceptions.ServiceUnavailable, 

632 ), 

633 deadline=60.0, 

634 ), 

635 default_timeout=60.0, 

636 client_info=client_info, 

637 ), 

638 self.list_schemas: self._wrap_method( 

639 self.list_schemas, 

640 default_retry=retries.AsyncRetry( 

641 initial=0.1, 

642 maximum=60.0, 

643 multiplier=1.3, 

644 predicate=retries.if_exception_type( 

645 core_exceptions.ServiceUnavailable, 

646 ), 

647 deadline=60.0, 

648 ), 

649 default_timeout=60.0, 

650 client_info=client_info, 

651 ), 

652 self.list_schema_revisions: self._wrap_method( 

653 self.list_schema_revisions, 

654 default_retry=retries.AsyncRetry( 

655 initial=0.1, 

656 maximum=60.0, 

657 multiplier=1.3, 

658 predicate=retries.if_exception_type( 

659 core_exceptions.ServiceUnavailable, 

660 ), 

661 deadline=60.0, 

662 ), 

663 default_timeout=60.0, 

664 client_info=client_info, 

665 ), 

666 self.commit_schema: self._wrap_method( 

667 self.commit_schema, 

668 default_retry=retries.AsyncRetry( 

669 initial=0.1, 

670 maximum=60.0, 

671 multiplier=1.3, 

672 predicate=retries.if_exception_type( 

673 core_exceptions.ServiceUnavailable, 

674 ), 

675 deadline=60.0, 

676 ), 

677 default_timeout=60.0, 

678 client_info=client_info, 

679 ), 

680 self.rollback_schema: self._wrap_method( 

681 self.rollback_schema, 

682 default_retry=retries.AsyncRetry( 

683 initial=0.1, 

684 maximum=60.0, 

685 multiplier=1.3, 

686 predicate=retries.if_exception_type( 

687 core_exceptions.ServiceUnavailable, 

688 ), 

689 deadline=60.0, 

690 ), 

691 default_timeout=60.0, 

692 client_info=client_info, 

693 ), 

694 self.delete_schema_revision: self._wrap_method( 

695 self.delete_schema_revision, 

696 default_retry=retries.AsyncRetry( 

697 initial=0.1, 

698 maximum=60.0, 

699 multiplier=1.3, 

700 predicate=retries.if_exception_type( 

701 core_exceptions.ServiceUnavailable, 

702 ), 

703 deadline=60.0, 

704 ), 

705 default_timeout=60.0, 

706 client_info=client_info, 

707 ), 

708 self.delete_schema: self._wrap_method( 

709 self.delete_schema, 

710 default_retry=retries.AsyncRetry( 

711 initial=0.1, 

712 maximum=60.0, 

713 multiplier=1.3, 

714 predicate=retries.if_exception_type( 

715 core_exceptions.ServiceUnavailable, 

716 ), 

717 deadline=60.0, 

718 ), 

719 default_timeout=60.0, 

720 client_info=client_info, 

721 ), 

722 self.validate_schema: self._wrap_method( 

723 self.validate_schema, 

724 default_retry=retries.AsyncRetry( 

725 initial=0.1, 

726 maximum=60.0, 

727 multiplier=1.3, 

728 predicate=retries.if_exception_type( 

729 core_exceptions.ServiceUnavailable, 

730 ), 

731 deadline=60.0, 

732 ), 

733 default_timeout=60.0, 

734 client_info=client_info, 

735 ), 

736 self.validate_message: self._wrap_method( 

737 self.validate_message, 

738 default_retry=retries.AsyncRetry( 

739 initial=0.1, 

740 maximum=60.0, 

741 multiplier=1.3, 

742 predicate=retries.if_exception_type( 

743 core_exceptions.ServiceUnavailable, 

744 ), 

745 deadline=60.0, 

746 ), 

747 default_timeout=60.0, 

748 client_info=client_info, 

749 ), 

750 self.get_iam_policy: self._wrap_method( 

751 self.get_iam_policy, 

752 default_timeout=None, 

753 client_info=client_info, 

754 ), 

755 self.set_iam_policy: self._wrap_method( 

756 self.set_iam_policy, 

757 default_timeout=None, 

758 client_info=client_info, 

759 ), 

760 self.test_iam_permissions: self._wrap_method( 

761 self.test_iam_permissions, 

762 default_timeout=None, 

763 client_info=client_info, 

764 ), 

765 } 

766 

767 def _wrap_method(self, func, *args, **kwargs): 

768 if self._wrap_with_kind: # pragma: NO COVER 

769 kwargs["kind"] = self.kind 

770 return gapic_v1.method_async.wrap_method(func, *args, **kwargs) 

771 

772 def close(self): 

773 return self._logged_channel.close() 

774 

775 @property 

776 def kind(self) -> str: 

777 return "grpc_asyncio" 

778 

779 @property 

780 def set_iam_policy( 

781 self, 

782 ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: 

783 r"""Return a callable for the set iam policy method over gRPC. 

784 Sets the IAM access control policy on the specified 

785 function. Replaces any existing policy. 

786 Returns: 

787 Callable[[~.SetIamPolicyRequest], 

788 ~.Policy]: 

789 A function that, when called, will call the underlying RPC 

790 on the server. 

791 """ 

792 # Generate a "stub function" on-the-fly which will actually make 

793 # the request. 

794 # gRPC handles serialization and deserialization, so we just need 

795 # to pass in the functions for each. 

796 if "set_iam_policy" not in self._stubs: 

797 self._stubs["set_iam_policy"] = self._logged_channel.unary_unary( 

798 "/google.iam.v1.IAMPolicy/SetIamPolicy", 

799 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, 

800 response_deserializer=policy_pb2.Policy.FromString, 

801 ) 

802 return self._stubs["set_iam_policy"] 

803 

804 @property 

805 def get_iam_policy( 

806 self, 

807 ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: 

808 r"""Return a callable for the get iam policy method over gRPC. 

809 Gets the IAM access control policy for a function. 

810 Returns an empty policy if the function exists and does 

811 not have a policy set. 

812 Returns: 

813 Callable[[~.GetIamPolicyRequest], 

814 ~.Policy]: 

815 A function that, when called, will call the underlying RPC 

816 on the server. 

817 """ 

818 # Generate a "stub function" on-the-fly which will actually make 

819 # the request. 

820 # gRPC handles serialization and deserialization, so we just need 

821 # to pass in the functions for each. 

822 if "get_iam_policy" not in self._stubs: 

823 self._stubs["get_iam_policy"] = self._logged_channel.unary_unary( 

824 "/google.iam.v1.IAMPolicy/GetIamPolicy", 

825 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, 

826 response_deserializer=policy_pb2.Policy.FromString, 

827 ) 

828 return self._stubs["get_iam_policy"] 

829 

830 @property 

831 def test_iam_permissions( 

832 self, 

833 ) -> Callable[ 

834 [iam_policy_pb2.TestIamPermissionsRequest], 

835 iam_policy_pb2.TestIamPermissionsResponse, 

836 ]: 

837 r"""Return a callable for the test iam permissions method over gRPC. 

838 Tests the specified permissions against the IAM access control 

839 policy for a function. If the function does not exist, this will 

840 return an empty set of permissions, not a NOT_FOUND error. 

841 Returns: 

842 Callable[[~.TestIamPermissionsRequest], 

843 ~.TestIamPermissionsResponse]: 

844 A function that, when called, will call the underlying RPC 

845 on the server. 

846 """ 

847 # Generate a "stub function" on-the-fly which will actually make 

848 # the request. 

849 # gRPC handles serialization and deserialization, so we just need 

850 # to pass in the functions for each. 

851 if "test_iam_permissions" not in self._stubs: 

852 self._stubs["test_iam_permissions"] = self._logged_channel.unary_unary( 

853 "/google.iam.v1.IAMPolicy/TestIamPermissions", 

854 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, 

855 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, 

856 ) 

857 return self._stubs["test_iam_permissions"] 

858 

859 

860__all__ = ("SchemaServiceGrpcAsyncIOTransport",)