Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.10/site-packages/google/pubsub_v1/services/schema_service/transports/grpc.py: 46%

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

131 statements  

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

2# Copyright 2024 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 json 

17import logging as std_logging 

18import pickle 

19import warnings 

20from typing import Callable, Dict, Optional, Sequence, Tuple, Union 

21 

22from google.api_core import grpc_helpers 

23from google.api_core import gapic_v1 

24import google.auth # type: ignore 

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

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

27from google.protobuf.json_format import MessageToJson 

28import google.protobuf.message 

29 

30import grpc # type: ignore 

31import proto # type: ignore 

32 

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

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

35from google.protobuf import empty_pb2 # type: ignore 

36from google.pubsub_v1.types import schema 

37from google.pubsub_v1.types import schema as gp_schema 

38from .base import SchemaServiceTransport, DEFAULT_CLIENT_INFO 

39 

40try: 

41 from google.api_core import client_logging # type: ignore 

42 

43 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

44except ImportError: # pragma: NO COVER 

45 CLIENT_LOGGING_SUPPORTED = False 

46 

47_LOGGER = std_logging.getLogger(__name__) 

48 

49 

50class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO COVER 

51 def intercept_unary_unary(self, continuation, client_call_details, request): 

52 logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

53 std_logging.DEBUG 

54 ) 

55 if logging_enabled: # pragma: NO COVER 

56 request_metadata = client_call_details.metadata 

57 if isinstance(request, proto.Message): 

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

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

60 request_payload = MessageToJson(request) 

61 else: 

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

63 

64 request_metadata = { 

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

66 for key, value in request_metadata 

67 } 

68 grpc_request = { 

69 "payload": request_payload, 

70 "requestMethod": "grpc", 

71 "metadata": dict(request_metadata), 

72 } 

73 _LOGGER.debug( 

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

75 extra={ 

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

77 "rpcName": client_call_details.method, 

78 "request": grpc_request, 

79 "metadata": grpc_request["metadata"], 

80 }, 

81 ) 

82 

83 response = continuation(client_call_details, request) 

84 if logging_enabled: # pragma: NO COVER 

85 response_metadata = response.trailing_metadata() 

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

87 metadata = ( 

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

89 if response_metadata 

90 else None 

91 ) 

92 result = response.result() 

93 if isinstance(result, proto.Message): 

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

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

96 response_payload = MessageToJson(result) 

97 else: 

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

99 grpc_response = { 

100 "payload": response_payload, 

101 "metadata": metadata, 

102 "status": "OK", 

103 } 

104 _LOGGER.debug( 

105 f"Received response for {client_call_details.method}.", 

106 extra={ 

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

108 "rpcName": client_call_details.method, 

109 "response": grpc_response, 

110 "metadata": grpc_response["metadata"], 

111 }, 

112 ) 

113 return response 

114 

115 

116class SchemaServiceGrpcTransport(SchemaServiceTransport): 

117 """gRPC backend transport for SchemaService. 

118 

119 Service for doing schema-related operations. 

120 

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

122 primary client can load the underlying transport implementation 

123 and call it. 

124 

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

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

127 """ 

128 

129 _stubs: Dict[str, Callable] 

130 

131 def __init__( 

132 self, 

133 *, 

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

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

136 credentials_file: Optional[str] = None, 

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

138 channel: Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]] = None, 

139 api_mtls_endpoint: Optional[str] = None, 

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

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

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

143 quota_project_id: Optional[str] = None, 

144 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

145 always_use_jwt_access: Optional[bool] = False, 

146 api_audience: Optional[str] = None, 

147 ) -> None: 

148 """Instantiate the transport. 

149 

150 Args: 

151 host (Optional[str]): 

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

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

154 authorization credentials to attach to requests. These 

155 credentials identify the application to the service; if none 

156 are specified, the client will attempt to ascertain the 

157 credentials from the environment. 

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

159 credentials_file (Optional[str]): A file with credentials that can 

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

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

162 scopes (Optional(Sequence[str])): A list of scopes. This argument is 

163 ignored if a ``channel`` instance is provided. 

164 channel (Optional[Union[grpc.Channel, Callable[..., grpc.Channel]]]): 

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

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

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

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

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

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

171 a mutual TLS channel with client SSL credentials from 

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

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

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

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

176 ``api_mtls_endpoint`` is None. 

177 ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials 

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

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

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

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

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

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

184 and quota. 

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

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

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

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

189 your own client library. 

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

191 be used for service account credentials. 

192 

193 Raises: 

194 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport 

195 creation failed for any reason. 

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

197 and ``credentials_file`` are passed. 

198 """ 

199 self._grpc_channel = None 

200 self._ssl_channel_credentials = ssl_channel_credentials 

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

202 

203 if api_mtls_endpoint: 

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

205 if client_cert_source: 

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

207 

208 if isinstance(channel, grpc.Channel): 

209 # Ignore credentials if a channel was passed. 

210 credentials = None 

211 self._ignore_credentials = True 

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

213 self._grpc_channel = channel 

214 self._ssl_channel_credentials = None 

215 

216 else: 

217 if api_mtls_endpoint: 

218 host = api_mtls_endpoint 

219 

220 # Create SSL credentials with client_cert_source or application 

221 # default SSL credentials. 

222 if client_cert_source: 

223 cert, key = client_cert_source() 

224 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

225 certificate_chain=cert, private_key=key 

226 ) 

227 else: 

228 self._ssl_channel_credentials = SslCredentials().ssl_credentials 

229 

230 else: 

231 if client_cert_source_for_mtls and not ssl_channel_credentials: 

232 cert, key = client_cert_source_for_mtls() 

233 self._ssl_channel_credentials = grpc.ssl_channel_credentials( 

234 certificate_chain=cert, private_key=key 

235 ) 

236 

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

238 super().__init__( 

239 host=host, 

240 credentials=credentials, 

241 credentials_file=credentials_file, 

242 scopes=scopes, 

243 quota_project_id=quota_project_id, 

244 client_info=client_info, 

245 always_use_jwt_access=always_use_jwt_access, 

246 api_audience=api_audience, 

247 ) 

248 

249 if not self._grpc_channel: 

250 # initialize with the provided callable or the default channel 

251 channel_init = channel or type(self).create_channel 

252 self._grpc_channel = channel_init( 

253 self._host, 

254 # use the credentials which are saved 

255 credentials=self._credentials, 

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

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

258 credentials_file=None, 

259 scopes=self._scopes, 

260 ssl_credentials=self._ssl_channel_credentials, 

261 quota_project_id=quota_project_id, 

262 options=[ 

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

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

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

266 ("grpc.keepalive_time_ms", 30000), 

267 ], 

268 ) 

269 

270 self._interceptor = _LoggingClientInterceptor() 

271 self._logged_channel = grpc.intercept_channel( 

272 self._grpc_channel, self._interceptor 

273 ) 

274 

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

276 self._prep_wrapped_messages(client_info) 

277 

278 @classmethod 

279 def create_channel( 

280 cls, 

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

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

283 credentials_file: Optional[str] = None, 

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

285 quota_project_id: Optional[str] = None, 

286 **kwargs, 

287 ) -> grpc.Channel: 

288 """Create and return a gRPC channel object. 

289 Args: 

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

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

292 authorization credentials to attach to requests. These 

293 credentials identify this application to the service. If 

294 none are specified, the client will attempt to ascertain 

295 the credentials from the environment. 

296 credentials_file (Optional[str]): A file with credentials that can 

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

298 This argument is mutually exclusive with credentials. 

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

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

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

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

303 and quota. 

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

305 channel creation. 

306 Returns: 

307 grpc.Channel: A gRPC channel object. 

308 

309 Raises: 

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

311 and ``credentials_file`` are passed. 

312 """ 

313 

314 return grpc_helpers.create_channel( 

315 host, 

316 credentials=credentials, 

317 credentials_file=credentials_file, 

318 quota_project_id=quota_project_id, 

319 default_scopes=cls.AUTH_SCOPES, 

320 scopes=scopes, 

321 default_host=cls.DEFAULT_HOST, 

322 **kwargs, 

323 ) 

324 

325 @property 

326 def grpc_channel(self) -> grpc.Channel: 

327 """Return the channel designed to connect to this service.""" 

328 return self._grpc_channel 

329 

330 @property 

331 def create_schema( 

332 self, 

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

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

335 

336 Creates a schema. 

337 

338 Returns: 

339 Callable[[~.CreateSchemaRequest], 

340 ~.Schema]: 

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

342 on the server. 

343 """ 

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

345 # the request. 

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

347 # to pass in the functions for each. 

348 if "create_schema" not in self._stubs: 

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

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

351 request_serializer=gp_schema.CreateSchemaRequest.serialize, 

352 response_deserializer=gp_schema.Schema.deserialize, 

353 ) 

354 return self._stubs["create_schema"] 

355 

356 @property 

357 def get_schema(self) -> Callable[[schema.GetSchemaRequest], schema.Schema]: 

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

359 

360 Gets a schema. 

361 

362 Returns: 

363 Callable[[~.GetSchemaRequest], 

364 ~.Schema]: 

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

366 on the server. 

367 """ 

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

369 # the request. 

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

371 # to pass in the functions for each. 

372 if "get_schema" not in self._stubs: 

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

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

375 request_serializer=schema.GetSchemaRequest.serialize, 

376 response_deserializer=schema.Schema.deserialize, 

377 ) 

378 return self._stubs["get_schema"] 

379 

380 @property 

381 def list_schemas( 

382 self, 

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

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

385 

386 Lists schemas in a project. 

387 

388 Returns: 

389 Callable[[~.ListSchemasRequest], 

390 ~.ListSchemasResponse]: 

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

392 on the server. 

393 """ 

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

395 # the request. 

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

397 # to pass in the functions for each. 

398 if "list_schemas" not in self._stubs: 

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

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

401 request_serializer=schema.ListSchemasRequest.serialize, 

402 response_deserializer=schema.ListSchemasResponse.deserialize, 

403 ) 

404 return self._stubs["list_schemas"] 

405 

406 @property 

407 def list_schema_revisions( 

408 self, 

409 ) -> Callable[ 

410 [schema.ListSchemaRevisionsRequest], schema.ListSchemaRevisionsResponse 

411 ]: 

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

413 

414 Lists all schema revisions for the named schema. 

415 

416 Returns: 

417 Callable[[~.ListSchemaRevisionsRequest], 

418 ~.ListSchemaRevisionsResponse]: 

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

420 on the server. 

421 """ 

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

423 # the request. 

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

425 # to pass in the functions for each. 

426 if "list_schema_revisions" not in self._stubs: 

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

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

429 request_serializer=schema.ListSchemaRevisionsRequest.serialize, 

430 response_deserializer=schema.ListSchemaRevisionsResponse.deserialize, 

431 ) 

432 return self._stubs["list_schema_revisions"] 

433 

434 @property 

435 def commit_schema( 

436 self, 

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

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

439 

440 Commits a new schema revision to an existing schema. 

441 

442 Returns: 

443 Callable[[~.CommitSchemaRequest], 

444 ~.Schema]: 

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

446 on the server. 

447 """ 

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

449 # the request. 

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

451 # to pass in the functions for each. 

452 if "commit_schema" not in self._stubs: 

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

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

455 request_serializer=gp_schema.CommitSchemaRequest.serialize, 

456 response_deserializer=gp_schema.Schema.deserialize, 

457 ) 

458 return self._stubs["commit_schema"] 

459 

460 @property 

461 def rollback_schema( 

462 self, 

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

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

465 

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

467 revision_id. 

468 

469 Returns: 

470 Callable[[~.RollbackSchemaRequest], 

471 ~.Schema]: 

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

473 on the server. 

474 """ 

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

476 # the request. 

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

478 # to pass in the functions for each. 

479 if "rollback_schema" not in self._stubs: 

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

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

482 request_serializer=schema.RollbackSchemaRequest.serialize, 

483 response_deserializer=schema.Schema.deserialize, 

484 ) 

485 return self._stubs["rollback_schema"] 

486 

487 @property 

488 def delete_schema_revision( 

489 self, 

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

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

492 

493 Deletes a specific schema revision. 

494 

495 Returns: 

496 Callable[[~.DeleteSchemaRevisionRequest], 

497 ~.Schema]: 

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

499 on the server. 

500 """ 

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

502 # the request. 

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

504 # to pass in the functions for each. 

505 if "delete_schema_revision" not in self._stubs: 

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

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

508 request_serializer=schema.DeleteSchemaRevisionRequest.serialize, 

509 response_deserializer=schema.Schema.deserialize, 

510 ) 

511 return self._stubs["delete_schema_revision"] 

512 

513 @property 

514 def delete_schema(self) -> Callable[[schema.DeleteSchemaRequest], empty_pb2.Empty]: 

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

516 

517 Deletes a schema. 

518 

519 Returns: 

520 Callable[[~.DeleteSchemaRequest], 

521 ~.Empty]: 

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

523 on the server. 

524 """ 

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

526 # the request. 

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

528 # to pass in the functions for each. 

529 if "delete_schema" not in self._stubs: 

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

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

532 request_serializer=schema.DeleteSchemaRequest.serialize, 

533 response_deserializer=empty_pb2.Empty.FromString, 

534 ) 

535 return self._stubs["delete_schema"] 

536 

537 @property 

538 def validate_schema( 

539 self, 

540 ) -> Callable[[gp_schema.ValidateSchemaRequest], gp_schema.ValidateSchemaResponse]: 

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

542 

543 Validates a schema. 

544 

545 Returns: 

546 Callable[[~.ValidateSchemaRequest], 

547 ~.ValidateSchemaResponse]: 

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

549 on the server. 

550 """ 

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

552 # the request. 

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

554 # to pass in the functions for each. 

555 if "validate_schema" not in self._stubs: 

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

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

558 request_serializer=gp_schema.ValidateSchemaRequest.serialize, 

559 response_deserializer=gp_schema.ValidateSchemaResponse.deserialize, 

560 ) 

561 return self._stubs["validate_schema"] 

562 

563 @property 

564 def validate_message( 

565 self, 

566 ) -> Callable[[schema.ValidateMessageRequest], schema.ValidateMessageResponse]: 

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

568 

569 Validates a message against a schema. 

570 

571 Returns: 

572 Callable[[~.ValidateMessageRequest], 

573 ~.ValidateMessageResponse]: 

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

575 on the server. 

576 """ 

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

578 # the request. 

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

580 # to pass in the functions for each. 

581 if "validate_message" not in self._stubs: 

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

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

584 request_serializer=schema.ValidateMessageRequest.serialize, 

585 response_deserializer=schema.ValidateMessageResponse.deserialize, 

586 ) 

587 return self._stubs["validate_message"] 

588 

589 def close(self): 

590 self._logged_channel.close() 

591 

592 @property 

593 def set_iam_policy( 

594 self, 

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

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

597 Sets the IAM access control policy on the specified 

598 function. Replaces any existing policy. 

599 Returns: 

600 Callable[[~.SetIamPolicyRequest], 

601 ~.Policy]: 

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

603 on the server. 

604 """ 

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

606 # the request. 

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

608 # to pass in the functions for each. 

609 if "set_iam_policy" not in self._stubs: 

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

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

612 request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, 

613 response_deserializer=policy_pb2.Policy.FromString, 

614 ) 

615 return self._stubs["set_iam_policy"] 

616 

617 @property 

618 def get_iam_policy( 

619 self, 

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

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

622 Gets the IAM access control policy for a function. 

623 Returns an empty policy if the function exists and does 

624 not have a policy set. 

625 Returns: 

626 Callable[[~.GetIamPolicyRequest], 

627 ~.Policy]: 

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

629 on the server. 

630 """ 

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

632 # the request. 

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

634 # to pass in the functions for each. 

635 if "get_iam_policy" not in self._stubs: 

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

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

638 request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, 

639 response_deserializer=policy_pb2.Policy.FromString, 

640 ) 

641 return self._stubs["get_iam_policy"] 

642 

643 @property 

644 def test_iam_permissions( 

645 self, 

646 ) -> Callable[ 

647 [iam_policy_pb2.TestIamPermissionsRequest], 

648 iam_policy_pb2.TestIamPermissionsResponse, 

649 ]: 

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

651 Tests the specified permissions against the IAM access control 

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

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

654 Returns: 

655 Callable[[~.TestIamPermissionsRequest], 

656 ~.TestIamPermissionsResponse]: 

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

658 on the server. 

659 """ 

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

661 # the request. 

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

663 # to pass in the functions for each. 

664 if "test_iam_permissions" not in self._stubs: 

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

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

667 request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, 

668 response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, 

669 ) 

670 return self._stubs["test_iam_permissions"] 

671 

672 @property 

673 def kind(self) -> str: 

674 return "grpc" 

675 

676 

677__all__ = ("SchemaServiceGrpcTransport",)