Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/pubsub_v1/services/schema_service/client.py: 31%

310 statements  

« 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# 

16from collections import OrderedDict 

17import functools 

18import os 

19import re 

20from typing import ( 

21 Dict, 

22 Mapping, 

23 MutableMapping, 

24 MutableSequence, 

25 Optional, 

26 Sequence, 

27 Tuple, 

28 Type, 

29 Union, 

30 cast, 

31) 

32 

33from google.pubsub_v1 import gapic_version as package_version 

34 

35from google.api_core import client_options as client_options_lib 

36from google.api_core import exceptions as core_exceptions 

37from google.api_core import gapic_v1 

38from google.api_core import retry as retries 

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

40from google.auth.transport import mtls # type: ignore 

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

42from google.auth.exceptions import MutualTLSChannelError # type: ignore 

43from google.oauth2 import service_account # type: ignore 

44 

45try: 

46 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] 

47except AttributeError: # pragma: NO COVER 

48 OptionalRetry = Union[retries.Retry, object] # type: ignore 

49 

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

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

52from google.protobuf import timestamp_pb2 # type: ignore 

53from google.pubsub_v1.services.schema_service import pagers 

54from google.pubsub_v1.types import schema 

55from google.pubsub_v1.types import schema as gp_schema 

56 

57import grpc 

58from .transports.base import SchemaServiceTransport, DEFAULT_CLIENT_INFO 

59from .transports.grpc import SchemaServiceGrpcTransport 

60from .transports.grpc_asyncio import SchemaServiceGrpcAsyncIOTransport 

61 

62 

63class SchemaServiceClientMeta(type): 

64 """Metaclass for the SchemaService client. 

65 

66 This provides class-level methods for building and retrieving 

67 support objects (e.g. transport) without polluting the client instance 

68 objects. 

69 """ 

70 

71 _transport_registry = OrderedDict() # type: Dict[str, Type[SchemaServiceTransport]] 

72 _transport_registry["grpc"] = SchemaServiceGrpcTransport 

73 _transport_registry["grpc_asyncio"] = SchemaServiceGrpcAsyncIOTransport 

74 

75 def get_transport_class( 

76 cls, 

77 label: Optional[str] = None, 

78 ) -> Type[SchemaServiceTransport]: 

79 """Returns an appropriate transport class. 

80 

81 Args: 

82 label: The name of the desired transport. If none is 

83 provided, then the first transport in the registry is used. 

84 

85 Returns: 

86 The transport class to use. 

87 """ 

88 # If a specific transport is requested, return that one. 

89 if label: 

90 return cls._transport_registry[label] 

91 

92 # No transport is requested; return the default (that is, the first one 

93 # in the dictionary). 

94 return next(iter(cls._transport_registry.values())) 

95 

96 

97class SchemaServiceClient(metaclass=SchemaServiceClientMeta): 

98 """Service for doing schema-related operations.""" 

99 

100 @staticmethod 

101 def _get_default_mtls_endpoint(api_endpoint): 

102 """Converts api endpoint to mTLS endpoint. 

103 

104 Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to 

105 "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. 

106 Args: 

107 api_endpoint (Optional[str]): the api endpoint to convert. 

108 Returns: 

109 str: converted mTLS api endpoint. 

110 """ 

111 if not api_endpoint: 

112 return api_endpoint 

113 

114 mtls_endpoint_re = re.compile( 

115 r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?" 

116 ) 

117 

118 m = mtls_endpoint_re.match(api_endpoint) 

119 name, mtls, sandbox, googledomain = m.groups() 

120 if mtls or not googledomain: 

121 return api_endpoint 

122 

123 if sandbox: 

124 return api_endpoint.replace( 

125 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" 

126 ) 

127 

128 return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") 

129 

130 DEFAULT_ENDPOINT = "pubsub.googleapis.com" 

131 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore 

132 DEFAULT_ENDPOINT 

133 ) 

134 

135 @classmethod 

136 def from_service_account_info(cls, info: dict, *args, **kwargs): 

137 """Creates an instance of this client using the provided credentials 

138 info. 

139 

140 Args: 

141 info (dict): The service account private key info. 

142 args: Additional arguments to pass to the constructor. 

143 kwargs: Additional arguments to pass to the constructor. 

144 

145 Returns: 

146 SchemaServiceClient: The constructed client. 

147 """ 

148 credentials = service_account.Credentials.from_service_account_info(info) 

149 kwargs["credentials"] = credentials 

150 return cls(*args, **kwargs) 

151 

152 @classmethod 

153 def from_service_account_file(cls, filename: str, *args, **kwargs): 

154 """Creates an instance of this client using the provided credentials 

155 file. 

156 

157 Args: 

158 filename (str): The path to the service account private key json 

159 file. 

160 args: Additional arguments to pass to the constructor. 

161 kwargs: Additional arguments to pass to the constructor. 

162 

163 Returns: 

164 SchemaServiceClient: The constructed client. 

165 """ 

166 credentials = service_account.Credentials.from_service_account_file(filename) 

167 kwargs["credentials"] = credentials 

168 return cls(*args, **kwargs) 

169 

170 from_service_account_json = from_service_account_file 

171 

172 @property 

173 def transport(self) -> SchemaServiceTransport: 

174 """Returns the transport used by the client instance. 

175 

176 Returns: 

177 SchemaServiceTransport: The transport used by the client 

178 instance. 

179 """ 

180 return self._transport 

181 

182 @staticmethod 

183 def schema_path( 

184 project: str, 

185 schema: str, 

186 ) -> str: 

187 """Returns a fully-qualified schema string.""" 

188 return "projects/{project}/schemas/{schema}".format( 

189 project=project, 

190 schema=schema, 

191 ) 

192 

193 @staticmethod 

194 def parse_schema_path(path: str) -> Dict[str, str]: 

195 """Parses a schema path into its component segments.""" 

196 m = re.match(r"^projects/(?P<project>.+?)/schemas/(?P<schema>.+?)$", path) 

197 return m.groupdict() if m else {} 

198 

199 @staticmethod 

200 def common_billing_account_path( 

201 billing_account: str, 

202 ) -> str: 

203 """Returns a fully-qualified billing_account string.""" 

204 return "billingAccounts/{billing_account}".format( 

205 billing_account=billing_account, 

206 ) 

207 

208 @staticmethod 

209 def parse_common_billing_account_path(path: str) -> Dict[str, str]: 

210 """Parse a billing_account path into its component segments.""" 

211 m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path) 

212 return m.groupdict() if m else {} 

213 

214 @staticmethod 

215 def common_folder_path( 

216 folder: str, 

217 ) -> str: 

218 """Returns a fully-qualified folder string.""" 

219 return "folders/{folder}".format( 

220 folder=folder, 

221 ) 

222 

223 @staticmethod 

224 def parse_common_folder_path(path: str) -> Dict[str, str]: 

225 """Parse a folder path into its component segments.""" 

226 m = re.match(r"^folders/(?P<folder>.+?)$", path) 

227 return m.groupdict() if m else {} 

228 

229 @staticmethod 

230 def common_organization_path( 

231 organization: str, 

232 ) -> str: 

233 """Returns a fully-qualified organization string.""" 

234 return "organizations/{organization}".format( 

235 organization=organization, 

236 ) 

237 

238 @staticmethod 

239 def parse_common_organization_path(path: str) -> Dict[str, str]: 

240 """Parse a organization path into its component segments.""" 

241 m = re.match(r"^organizations/(?P<organization>.+?)$", path) 

242 return m.groupdict() if m else {} 

243 

244 @staticmethod 

245 def common_project_path( 

246 project: str, 

247 ) -> str: 

248 """Returns a fully-qualified project string.""" 

249 return "projects/{project}".format( 

250 project=project, 

251 ) 

252 

253 @staticmethod 

254 def parse_common_project_path(path: str) -> Dict[str, str]: 

255 """Parse a project path into its component segments.""" 

256 m = re.match(r"^projects/(?P<project>.+?)$", path) 

257 return m.groupdict() if m else {} 

258 

259 @staticmethod 

260 def common_location_path( 

261 project: str, 

262 location: str, 

263 ) -> str: 

264 """Returns a fully-qualified location string.""" 

265 return "projects/{project}/locations/{location}".format( 

266 project=project, 

267 location=location, 

268 ) 

269 

270 @staticmethod 

271 def parse_common_location_path(path: str) -> Dict[str, str]: 

272 """Parse a location path into its component segments.""" 

273 m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path) 

274 return m.groupdict() if m else {} 

275 

276 @classmethod 

277 def get_mtls_endpoint_and_cert_source( 

278 cls, client_options: Optional[client_options_lib.ClientOptions] = None 

279 ): 

280 """Return the API endpoint and client cert source for mutual TLS. 

281 

282 The client cert source is determined in the following order: 

283 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the 

284 client cert source is None. 

285 (2) if `client_options.client_cert_source` is provided, use the provided one; if the 

286 default client cert source exists, use the default one; otherwise the client cert 

287 source is None. 

288 

289 The API endpoint is determined in the following order: 

290 (1) if `client_options.api_endpoint` if provided, use the provided one. 

291 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the 

292 default mTLS endpoint; if the environment variable is "never", use the default API 

293 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise 

294 use the default API endpoint. 

295 

296 More details can be found at https://google.aip.dev/auth/4114. 

297 

298 Args: 

299 client_options (google.api_core.client_options.ClientOptions): Custom options for the 

300 client. Only the `api_endpoint` and `client_cert_source` properties may be used 

301 in this method. 

302 

303 Returns: 

304 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the 

305 client cert source to use. 

306 

307 Raises: 

308 google.auth.exceptions.MutualTLSChannelError: If any errors happen. 

309 """ 

310 if client_options is None: 

311 client_options = client_options_lib.ClientOptions() 

312 use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") 

313 use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") 

314 if use_client_cert not in ("true", "false"): 

315 raise ValueError( 

316 "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" 

317 ) 

318 if use_mtls_endpoint not in ("auto", "never", "always"): 

319 raise MutualTLSChannelError( 

320 "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" 

321 ) 

322 

323 # Figure out the client cert source to use. 

324 client_cert_source = None 

325 if use_client_cert == "true": 

326 if client_options.client_cert_source: 

327 client_cert_source = client_options.client_cert_source 

328 elif mtls.has_default_client_cert_source(): 

329 client_cert_source = mtls.default_client_cert_source() 

330 

331 # Figure out which api endpoint to use. 

332 if client_options.api_endpoint is not None: 

333 api_endpoint = client_options.api_endpoint 

334 elif use_mtls_endpoint == "always" or ( 

335 use_mtls_endpoint == "auto" and client_cert_source 

336 ): 

337 api_endpoint = cls.DEFAULT_MTLS_ENDPOINT 

338 else: 

339 api_endpoint = cls.DEFAULT_ENDPOINT 

340 

341 return api_endpoint, client_cert_source 

342 

343 def __init__( 

344 self, 

345 *, 

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

347 transport: Optional[Union[str, SchemaServiceTransport]] = None, 

348 client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, 

349 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

350 ) -> None: 

351 """Instantiates the schema service client. 

352 

353 Args: 

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

355 authorization credentials to attach to requests. These 

356 credentials identify the application to the service; if none 

357 are specified, the client will attempt to ascertain the 

358 credentials from the environment. 

359 transport (Union[str, SchemaServiceTransport]): The 

360 transport to use. If set to None, a transport is chosen 

361 automatically. 

362 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the 

363 client. It won't take effect if a ``transport`` instance is provided. 

364 (1) The ``api_endpoint`` property can be used to override the 

365 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 

366 environment variable can also be used to override the endpoint: 

367 "always" (always use the default mTLS endpoint), "never" (always 

368 use the default regular endpoint) and "auto" (auto switch to the 

369 default mTLS endpoint if client certificate is present, this is 

370 the default value). However, the ``api_endpoint`` property takes 

371 precedence if provided. 

372 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

373 is "true", then the ``client_cert_source`` property can be used 

374 to provide client certificate for mutual TLS transport. If 

375 not provided, the default SSL client certificate will be used if 

376 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

377 set, no client certificate will be used. 

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

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

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

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

382 your own client library. 

383 

384 Raises: 

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

386 creation failed for any reason. 

387 """ 

388 if isinstance(client_options, dict): 

389 client_options = client_options_lib.from_dict(client_options) 

390 if client_options is None: 

391 client_options = client_options_lib.ClientOptions() 

392 client_options = cast(client_options_lib.ClientOptions, client_options) 

393 

394 api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( 

395 client_options 

396 ) 

397 

398 api_key_value = getattr(client_options, "api_key", None) 

399 if api_key_value and credentials: 

400 raise ValueError( 

401 "client_options.api_key and credentials are mutually exclusive" 

402 ) 

403 

404 # Save or instantiate the transport. 

405 # Ordinarily, we provide the transport, but allowing a custom transport 

406 # instance provides an extensibility point for unusual situations. 

407 if isinstance(transport, SchemaServiceTransport): 

408 # transport is a SchemaServiceTransport instance. 

409 if credentials or client_options.credentials_file or api_key_value: 

410 raise ValueError( 

411 "When providing a transport instance, " 

412 "provide its credentials directly." 

413 ) 

414 if client_options.scopes: 

415 raise ValueError( 

416 "When providing a transport instance, provide its scopes " 

417 "directly." 

418 ) 

419 self._transport = transport 

420 else: 

421 import google.auth._default # type: ignore 

422 

423 if api_key_value and hasattr( 

424 google.auth._default, "get_api_key_credentials" 

425 ): 

426 credentials = google.auth._default.get_api_key_credentials( 

427 api_key_value 

428 ) 

429 

430 Transport = type(self).get_transport_class(transport) 

431 

432 emulator_host = os.environ.get("PUBSUB_EMULATOR_HOST") 

433 if emulator_host: 

434 if issubclass(Transport, type(self)._transport_registry["grpc"]): 

435 channel = grpc.insecure_channel(target=emulator_host) 

436 else: 

437 channel = grpc.aio.insecure_channel(target=emulator_host) 

438 Transport = functools.partial(Transport, channel=channel) 

439 

440 self._transport = Transport( 

441 credentials=credentials, 

442 credentials_file=client_options.credentials_file, 

443 host=api_endpoint, 

444 scopes=client_options.scopes, 

445 client_cert_source_for_mtls=client_cert_source_func, 

446 quota_project_id=client_options.quota_project_id, 

447 client_info=client_info, 

448 always_use_jwt_access=True, 

449 api_audience=client_options.api_audience, 

450 ) 

451 

452 def create_schema( 

453 self, 

454 request: Optional[Union[gp_schema.CreateSchemaRequest, dict]] = None, 

455 *, 

456 parent: Optional[str] = None, 

457 schema: Optional[gp_schema.Schema] = None, 

458 schema_id: Optional[str] = None, 

459 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

460 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

461 metadata: Sequence[Tuple[str, str]] = (), 

462 ) -> gp_schema.Schema: 

463 r"""Creates a schema. 

464 

465 .. code-block:: python 

466 

467 # This snippet has been automatically generated and should be regarded as a 

468 # code template only. 

469 # It will require modifications to work: 

470 # - It may require correct/in-range values for request initialization. 

471 # - It may require specifying regional endpoints when creating the service 

472 # client as shown in: 

473 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

474 from google import pubsub_v1 

475 

476 def sample_create_schema(): 

477 # Create a client 

478 client = pubsub_v1.SchemaServiceClient() 

479 

480 # Initialize request argument(s) 

481 schema = pubsub_v1.Schema() 

482 schema.name = "name_value" 

483 

484 request = pubsub_v1.CreateSchemaRequest( 

485 parent="parent_value", 

486 schema=schema, 

487 ) 

488 

489 # Make the request 

490 response = client.create_schema(request=request) 

491 

492 # Handle the response 

493 print(response) 

494 

495 Args: 

496 request (Union[google.pubsub_v1.types.CreateSchemaRequest, dict]): 

497 The request object. Request for the CreateSchema method. 

498 parent (str): 

499 Required. The name of the project in which to create the 

500 schema. Format is ``projects/{project-id}``. 

501 

502 This corresponds to the ``parent`` field 

503 on the ``request`` instance; if ``request`` is provided, this 

504 should not be set. 

505 schema (google.pubsub_v1.types.Schema): 

506 Required. The schema object to create. 

507 

508 This schema's ``name`` parameter is ignored. The schema 

509 object returned by CreateSchema will have a ``name`` 

510 made using the given ``parent`` and ``schema_id``. 

511 

512 This corresponds to the ``schema`` field 

513 on the ``request`` instance; if ``request`` is provided, this 

514 should not be set. 

515 schema_id (str): 

516 The ID to use for the schema, which will become the 

517 final component of the schema's resource name. 

518 

519 See 

520 https://cloud.google.com/pubsub/docs/admin#resource_names 

521 for resource name constraints. 

522 

523 This corresponds to the ``schema_id`` field 

524 on the ``request`` instance; if ``request`` is provided, this 

525 should not be set. 

526 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

527 should be retried. 

528 timeout (float): The timeout for this request. 

529 metadata (Sequence[Tuple[str, str]]): Strings which should be 

530 sent along with the request as metadata. 

531 

532 Returns: 

533 google.pubsub_v1.types.Schema: 

534 A schema resource. 

535 """ 

536 # Create or coerce a protobuf request object. 

537 # Quick check: If we got a request object, we should *not* have 

538 # gotten any keyword arguments that map to the request. 

539 has_flattened_params = any([parent, schema, schema_id]) 

540 if request is not None and has_flattened_params: 

541 raise ValueError( 

542 "If the `request` argument is set, then none of " 

543 "the individual field arguments should be set." 

544 ) 

545 

546 # Minor optimization to avoid making a copy if the user passes 

547 # in a gp_schema.CreateSchemaRequest. 

548 # There's no risk of modifying the input as we've already verified 

549 # there are no flattened fields. 

550 if not isinstance(request, gp_schema.CreateSchemaRequest): 

551 request = gp_schema.CreateSchemaRequest(request) 

552 # If we have keyword arguments corresponding to fields on the 

553 # request, apply these. 

554 if parent is not None: 

555 request.parent = parent 

556 if schema is not None: 

557 request.schema = schema 

558 if schema_id is not None: 

559 request.schema_id = schema_id 

560 

561 # Wrap the RPC method; this adds retry and timeout information, 

562 # and friendly error handling. 

563 rpc = self._transport._wrapped_methods[self._transport.create_schema] 

564 

565 # Certain fields should be provided within the metadata header; 

566 # add these here. 

567 metadata = tuple(metadata) + ( 

568 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

569 ) 

570 

571 # Send the request. 

572 response = rpc( 

573 request, 

574 retry=retry, 

575 timeout=timeout, 

576 metadata=metadata, 

577 ) 

578 

579 # Done; return the response. 

580 return response 

581 

582 def get_schema( 

583 self, 

584 request: Optional[Union[schema.GetSchemaRequest, dict]] = None, 

585 *, 

586 name: Optional[str] = None, 

587 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

588 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

589 metadata: Sequence[Tuple[str, str]] = (), 

590 ) -> schema.Schema: 

591 r"""Gets a schema. 

592 

593 .. code-block:: python 

594 

595 # This snippet has been automatically generated and should be regarded as a 

596 # code template only. 

597 # It will require modifications to work: 

598 # - It may require correct/in-range values for request initialization. 

599 # - It may require specifying regional endpoints when creating the service 

600 # client as shown in: 

601 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

602 from google import pubsub_v1 

603 

604 def sample_get_schema(): 

605 # Create a client 

606 client = pubsub_v1.SchemaServiceClient() 

607 

608 # Initialize request argument(s) 

609 request = pubsub_v1.GetSchemaRequest( 

610 name="name_value", 

611 ) 

612 

613 # Make the request 

614 response = client.get_schema(request=request) 

615 

616 # Handle the response 

617 print(response) 

618 

619 Args: 

620 request (Union[google.pubsub_v1.types.GetSchemaRequest, dict]): 

621 The request object. Request for the GetSchema method. 

622 name (str): 

623 Required. The name of the schema to get. Format is 

624 ``projects/{project}/schemas/{schema}``. 

625 

626 This corresponds to the ``name`` field 

627 on the ``request`` instance; if ``request`` is provided, this 

628 should not be set. 

629 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

630 should be retried. 

631 timeout (float): The timeout for this request. 

632 metadata (Sequence[Tuple[str, str]]): Strings which should be 

633 sent along with the request as metadata. 

634 

635 Returns: 

636 google.pubsub_v1.types.Schema: 

637 A schema resource. 

638 """ 

639 # Create or coerce a protobuf request object. 

640 # Quick check: If we got a request object, we should *not* have 

641 # gotten any keyword arguments that map to the request. 

642 has_flattened_params = any([name]) 

643 if request is not None and has_flattened_params: 

644 raise ValueError( 

645 "If the `request` argument is set, then none of " 

646 "the individual field arguments should be set." 

647 ) 

648 

649 # Minor optimization to avoid making a copy if the user passes 

650 # in a schema.GetSchemaRequest. 

651 # There's no risk of modifying the input as we've already verified 

652 # there are no flattened fields. 

653 if not isinstance(request, schema.GetSchemaRequest): 

654 request = schema.GetSchemaRequest(request) 

655 # If we have keyword arguments corresponding to fields on the 

656 # request, apply these. 

657 if name is not None: 

658 request.name = name 

659 

660 # Wrap the RPC method; this adds retry and timeout information, 

661 # and friendly error handling. 

662 rpc = self._transport._wrapped_methods[self._transport.get_schema] 

663 

664 # Certain fields should be provided within the metadata header; 

665 # add these here. 

666 metadata = tuple(metadata) + ( 

667 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

668 ) 

669 

670 # Send the request. 

671 response = rpc( 

672 request, 

673 retry=retry, 

674 timeout=timeout, 

675 metadata=metadata, 

676 ) 

677 

678 # Done; return the response. 

679 return response 

680 

681 def list_schemas( 

682 self, 

683 request: Optional[Union[schema.ListSchemasRequest, dict]] = None, 

684 *, 

685 parent: Optional[str] = None, 

686 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

687 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

688 metadata: Sequence[Tuple[str, str]] = (), 

689 ) -> pagers.ListSchemasPager: 

690 r"""Lists schemas in a project. 

691 

692 .. code-block:: python 

693 

694 # This snippet has been automatically generated and should be regarded as a 

695 # code template only. 

696 # It will require modifications to work: 

697 # - It may require correct/in-range values for request initialization. 

698 # - It may require specifying regional endpoints when creating the service 

699 # client as shown in: 

700 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

701 from google import pubsub_v1 

702 

703 def sample_list_schemas(): 

704 # Create a client 

705 client = pubsub_v1.SchemaServiceClient() 

706 

707 # Initialize request argument(s) 

708 request = pubsub_v1.ListSchemasRequest( 

709 parent="parent_value", 

710 ) 

711 

712 # Make the request 

713 page_result = client.list_schemas(request=request) 

714 

715 # Handle the response 

716 for response in page_result: 

717 print(response) 

718 

719 Args: 

720 request (Union[google.pubsub_v1.types.ListSchemasRequest, dict]): 

721 The request object. Request for the `ListSchemas` 

722 method. 

723 parent (str): 

724 Required. The name of the project in which to list 

725 schemas. Format is ``projects/{project-id}``. 

726 

727 This corresponds to the ``parent`` field 

728 on the ``request`` instance; if ``request`` is provided, this 

729 should not be set. 

730 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

731 should be retried. 

732 timeout (float): The timeout for this request. 

733 metadata (Sequence[Tuple[str, str]]): Strings which should be 

734 sent along with the request as metadata. 

735 

736 Returns: 

737 google.pubsub_v1.services.schema_service.pagers.ListSchemasPager: 

738 Response for the ListSchemas method. 

739 

740 Iterating over this object will yield results and 

741 resolve additional pages automatically. 

742 

743 """ 

744 # Create or coerce a protobuf request object. 

745 # Quick check: If we got a request object, we should *not* have 

746 # gotten any keyword arguments that map to the request. 

747 has_flattened_params = any([parent]) 

748 if request is not None and has_flattened_params: 

749 raise ValueError( 

750 "If the `request` argument is set, then none of " 

751 "the individual field arguments should be set." 

752 ) 

753 

754 # Minor optimization to avoid making a copy if the user passes 

755 # in a schema.ListSchemasRequest. 

756 # There's no risk of modifying the input as we've already verified 

757 # there are no flattened fields. 

758 if not isinstance(request, schema.ListSchemasRequest): 

759 request = schema.ListSchemasRequest(request) 

760 # If we have keyword arguments corresponding to fields on the 

761 # request, apply these. 

762 if parent is not None: 

763 request.parent = parent 

764 

765 # Wrap the RPC method; this adds retry and timeout information, 

766 # and friendly error handling. 

767 rpc = self._transport._wrapped_methods[self._transport.list_schemas] 

768 

769 # Certain fields should be provided within the metadata header; 

770 # add these here. 

771 metadata = tuple(metadata) + ( 

772 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

773 ) 

774 

775 # Send the request. 

776 response = rpc( 

777 request, 

778 retry=retry, 

779 timeout=timeout, 

780 metadata=metadata, 

781 ) 

782 

783 # This method is paged; wrap the response in a pager, which provides 

784 # an `__iter__` convenience method. 

785 response = pagers.ListSchemasPager( 

786 method=rpc, 

787 request=request, 

788 response=response, 

789 metadata=metadata, 

790 ) 

791 

792 # Done; return the response. 

793 return response 

794 

795 def list_schema_revisions( 

796 self, 

797 request: Optional[Union[schema.ListSchemaRevisionsRequest, dict]] = None, 

798 *, 

799 name: Optional[str] = None, 

800 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

801 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

802 metadata: Sequence[Tuple[str, str]] = (), 

803 ) -> pagers.ListSchemaRevisionsPager: 

804 r"""Lists all schema revisions for the named schema. 

805 

806 .. code-block:: python 

807 

808 # This snippet has been automatically generated and should be regarded as a 

809 # code template only. 

810 # It will require modifications to work: 

811 # - It may require correct/in-range values for request initialization. 

812 # - It may require specifying regional endpoints when creating the service 

813 # client as shown in: 

814 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

815 from google import pubsub_v1 

816 

817 def sample_list_schema_revisions(): 

818 # Create a client 

819 client = pubsub_v1.SchemaServiceClient() 

820 

821 # Initialize request argument(s) 

822 request = pubsub_v1.ListSchemaRevisionsRequest( 

823 name="name_value", 

824 ) 

825 

826 # Make the request 

827 page_result = client.list_schema_revisions(request=request) 

828 

829 # Handle the response 

830 for response in page_result: 

831 print(response) 

832 

833 Args: 

834 request (Union[google.pubsub_v1.types.ListSchemaRevisionsRequest, dict]): 

835 The request object. Request for the 

836 `ListSchemaRevisions` method. 

837 name (str): 

838 Required. The name of the schema to 

839 list revisions for. 

840 

841 This corresponds to the ``name`` field 

842 on the ``request`` instance; if ``request`` is provided, this 

843 should not be set. 

844 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

845 should be retried. 

846 timeout (float): The timeout for this request. 

847 metadata (Sequence[Tuple[str, str]]): Strings which should be 

848 sent along with the request as metadata. 

849 

850 Returns: 

851 google.pubsub_v1.services.schema_service.pagers.ListSchemaRevisionsPager: 

852 Response for the ListSchemaRevisions method. 

853 

854 Iterating over this object will yield results and 

855 resolve additional pages automatically. 

856 

857 """ 

858 # Create or coerce a protobuf request object. 

859 # Quick check: If we got a request object, we should *not* have 

860 # gotten any keyword arguments that map to the request. 

861 has_flattened_params = any([name]) 

862 if request is not None and has_flattened_params: 

863 raise ValueError( 

864 "If the `request` argument is set, then none of " 

865 "the individual field arguments should be set." 

866 ) 

867 

868 # Minor optimization to avoid making a copy if the user passes 

869 # in a schema.ListSchemaRevisionsRequest. 

870 # There's no risk of modifying the input as we've already verified 

871 # there are no flattened fields. 

872 if not isinstance(request, schema.ListSchemaRevisionsRequest): 

873 request = schema.ListSchemaRevisionsRequest(request) 

874 # If we have keyword arguments corresponding to fields on the 

875 # request, apply these. 

876 if name is not None: 

877 request.name = name 

878 

879 # Wrap the RPC method; this adds retry and timeout information, 

880 # and friendly error handling. 

881 rpc = self._transport._wrapped_methods[self._transport.list_schema_revisions] 

882 

883 # Certain fields should be provided within the metadata header; 

884 # add these here. 

885 metadata = tuple(metadata) + ( 

886 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

887 ) 

888 

889 # Send the request. 

890 response = rpc( 

891 request, 

892 retry=retry, 

893 timeout=timeout, 

894 metadata=metadata, 

895 ) 

896 

897 # This method is paged; wrap the response in a pager, which provides 

898 # an `__iter__` convenience method. 

899 response = pagers.ListSchemaRevisionsPager( 

900 method=rpc, 

901 request=request, 

902 response=response, 

903 metadata=metadata, 

904 ) 

905 

906 # Done; return the response. 

907 return response 

908 

909 def commit_schema( 

910 self, 

911 request: Optional[Union[gp_schema.CommitSchemaRequest, dict]] = None, 

912 *, 

913 name: Optional[str] = None, 

914 schema: Optional[gp_schema.Schema] = None, 

915 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

916 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

917 metadata: Sequence[Tuple[str, str]] = (), 

918 ) -> gp_schema.Schema: 

919 r"""Commits a new schema revision to an existing schema. 

920 

921 .. code-block:: python 

922 

923 # This snippet has been automatically generated and should be regarded as a 

924 # code template only. 

925 # It will require modifications to work: 

926 # - It may require correct/in-range values for request initialization. 

927 # - It may require specifying regional endpoints when creating the service 

928 # client as shown in: 

929 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

930 from google import pubsub_v1 

931 

932 def sample_commit_schema(): 

933 # Create a client 

934 client = pubsub_v1.SchemaServiceClient() 

935 

936 # Initialize request argument(s) 

937 schema = pubsub_v1.Schema() 

938 schema.name = "name_value" 

939 

940 request = pubsub_v1.CommitSchemaRequest( 

941 name="name_value", 

942 schema=schema, 

943 ) 

944 

945 # Make the request 

946 response = client.commit_schema(request=request) 

947 

948 # Handle the response 

949 print(response) 

950 

951 Args: 

952 request (Union[google.pubsub_v1.types.CommitSchemaRequest, dict]): 

953 The request object. Request for CommitSchema method. 

954 name (str): 

955 Required. The name of the schema we are revising. Format 

956 is ``projects/{project}/schemas/{schema}``. 

957 

958 This corresponds to the ``name`` field 

959 on the ``request`` instance; if ``request`` is provided, this 

960 should not be set. 

961 schema (google.pubsub_v1.types.Schema): 

962 Required. The schema revision to 

963 commit. 

964 

965 This corresponds to the ``schema`` field 

966 on the ``request`` instance; if ``request`` is provided, this 

967 should not be set. 

968 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

969 should be retried. 

970 timeout (float): The timeout for this request. 

971 metadata (Sequence[Tuple[str, str]]): Strings which should be 

972 sent along with the request as metadata. 

973 

974 Returns: 

975 google.pubsub_v1.types.Schema: 

976 A schema resource. 

977 """ 

978 # Create or coerce a protobuf request object. 

979 # Quick check: If we got a request object, we should *not* have 

980 # gotten any keyword arguments that map to the request. 

981 has_flattened_params = any([name, schema]) 

982 if request is not None and has_flattened_params: 

983 raise ValueError( 

984 "If the `request` argument is set, then none of " 

985 "the individual field arguments should be set." 

986 ) 

987 

988 # Minor optimization to avoid making a copy if the user passes 

989 # in a gp_schema.CommitSchemaRequest. 

990 # There's no risk of modifying the input as we've already verified 

991 # there are no flattened fields. 

992 if not isinstance(request, gp_schema.CommitSchemaRequest): 

993 request = gp_schema.CommitSchemaRequest(request) 

994 # If we have keyword arguments corresponding to fields on the 

995 # request, apply these. 

996 if name is not None: 

997 request.name = name 

998 if schema is not None: 

999 request.schema = schema 

1000 

1001 # Wrap the RPC method; this adds retry and timeout information, 

1002 # and friendly error handling. 

1003 rpc = self._transport._wrapped_methods[self._transport.commit_schema] 

1004 

1005 # Certain fields should be provided within the metadata header; 

1006 # add these here. 

1007 metadata = tuple(metadata) + ( 

1008 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1009 ) 

1010 

1011 # Send the request. 

1012 response = rpc( 

1013 request, 

1014 retry=retry, 

1015 timeout=timeout, 

1016 metadata=metadata, 

1017 ) 

1018 

1019 # Done; return the response. 

1020 return response 

1021 

1022 def rollback_schema( 

1023 self, 

1024 request: Optional[Union[schema.RollbackSchemaRequest, dict]] = None, 

1025 *, 

1026 name: Optional[str] = None, 

1027 revision_id: Optional[str] = None, 

1028 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1029 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1030 metadata: Sequence[Tuple[str, str]] = (), 

1031 ) -> schema.Schema: 

1032 r"""Creates a new schema revision that is a copy of the provided 

1033 revision_id. 

1034 

1035 .. code-block:: python 

1036 

1037 # This snippet has been automatically generated and should be regarded as a 

1038 # code template only. 

1039 # It will require modifications to work: 

1040 # - It may require correct/in-range values for request initialization. 

1041 # - It may require specifying regional endpoints when creating the service 

1042 # client as shown in: 

1043 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1044 from google import pubsub_v1 

1045 

1046 def sample_rollback_schema(): 

1047 # Create a client 

1048 client = pubsub_v1.SchemaServiceClient() 

1049 

1050 # Initialize request argument(s) 

1051 request = pubsub_v1.RollbackSchemaRequest( 

1052 name="name_value", 

1053 revision_id="revision_id_value", 

1054 ) 

1055 

1056 # Make the request 

1057 response = client.rollback_schema(request=request) 

1058 

1059 # Handle the response 

1060 print(response) 

1061 

1062 Args: 

1063 request (Union[google.pubsub_v1.types.RollbackSchemaRequest, dict]): 

1064 The request object. Request for the `RollbackSchema` 

1065 method. 

1066 name (str): 

1067 Required. The schema being rolled 

1068 back with revision id. 

1069 

1070 This corresponds to the ``name`` field 

1071 on the ``request`` instance; if ``request`` is provided, this 

1072 should not be set. 

1073 revision_id (str): 

1074 Required. The revision ID to roll 

1075 back to. It must be a revision of the 

1076 same schema. 

1077 Example: c7cfa2a8 

1078 

1079 This corresponds to the ``revision_id`` field 

1080 on the ``request`` instance; if ``request`` is provided, this 

1081 should not be set. 

1082 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1083 should be retried. 

1084 timeout (float): The timeout for this request. 

1085 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1086 sent along with the request as metadata. 

1087 

1088 Returns: 

1089 google.pubsub_v1.types.Schema: 

1090 A schema resource. 

1091 """ 

1092 # Create or coerce a protobuf request object. 

1093 # Quick check: If we got a request object, we should *not* have 

1094 # gotten any keyword arguments that map to the request. 

1095 has_flattened_params = any([name, revision_id]) 

1096 if request is not None and has_flattened_params: 

1097 raise ValueError( 

1098 "If the `request` argument is set, then none of " 

1099 "the individual field arguments should be set." 

1100 ) 

1101 

1102 # Minor optimization to avoid making a copy if the user passes 

1103 # in a schema.RollbackSchemaRequest. 

1104 # There's no risk of modifying the input as we've already verified 

1105 # there are no flattened fields. 

1106 if not isinstance(request, schema.RollbackSchemaRequest): 

1107 request = schema.RollbackSchemaRequest(request) 

1108 # If we have keyword arguments corresponding to fields on the 

1109 # request, apply these. 

1110 if name is not None: 

1111 request.name = name 

1112 if revision_id is not None: 

1113 request.revision_id = revision_id 

1114 

1115 # Wrap the RPC method; this adds retry and timeout information, 

1116 # and friendly error handling. 

1117 rpc = self._transport._wrapped_methods[self._transport.rollback_schema] 

1118 

1119 # Certain fields should be provided within the metadata header; 

1120 # add these here. 

1121 metadata = tuple(metadata) + ( 

1122 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1123 ) 

1124 

1125 # Send the request. 

1126 response = rpc( 

1127 request, 

1128 retry=retry, 

1129 timeout=timeout, 

1130 metadata=metadata, 

1131 ) 

1132 

1133 # Done; return the response. 

1134 return response 

1135 

1136 def delete_schema_revision( 

1137 self, 

1138 request: Optional[Union[schema.DeleteSchemaRevisionRequest, dict]] = None, 

1139 *, 

1140 name: Optional[str] = None, 

1141 revision_id: Optional[str] = None, 

1142 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1143 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1144 metadata: Sequence[Tuple[str, str]] = (), 

1145 ) -> schema.Schema: 

1146 r"""Deletes a specific schema revision. 

1147 

1148 .. code-block:: python 

1149 

1150 # This snippet has been automatically generated and should be regarded as a 

1151 # code template only. 

1152 # It will require modifications to work: 

1153 # - It may require correct/in-range values for request initialization. 

1154 # - It may require specifying regional endpoints when creating the service 

1155 # client as shown in: 

1156 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1157 from google import pubsub_v1 

1158 

1159 def sample_delete_schema_revision(): 

1160 # Create a client 

1161 client = pubsub_v1.SchemaServiceClient() 

1162 

1163 # Initialize request argument(s) 

1164 request = pubsub_v1.DeleteSchemaRevisionRequest( 

1165 name="name_value", 

1166 ) 

1167 

1168 # Make the request 

1169 response = client.delete_schema_revision(request=request) 

1170 

1171 # Handle the response 

1172 print(response) 

1173 

1174 Args: 

1175 request (Union[google.pubsub_v1.types.DeleteSchemaRevisionRequest, dict]): 

1176 The request object. Request for the 

1177 `DeleteSchemaRevision` method. 

1178 name (str): 

1179 Required. The name of the schema revision to be deleted, 

1180 with a revision ID explicitly included. 

1181 

1182 Example: ``projects/123/schemas/my-schema@c7cfa2a8`` 

1183 

1184 This corresponds to the ``name`` field 

1185 on the ``request`` instance; if ``request`` is provided, this 

1186 should not be set. 

1187 revision_id (str): 

1188 Optional. This field is deprecated and should not be 

1189 used for specifying the revision ID. The revision ID 

1190 should be specified via the ``name`` parameter. 

1191 

1192 This corresponds to the ``revision_id`` field 

1193 on the ``request`` instance; if ``request`` is provided, this 

1194 should not be set. 

1195 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1196 should be retried. 

1197 timeout (float): The timeout for this request. 

1198 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1199 sent along with the request as metadata. 

1200 

1201 Returns: 

1202 google.pubsub_v1.types.Schema: 

1203 A schema resource. 

1204 """ 

1205 # Create or coerce a protobuf request object. 

1206 # Quick check: If we got a request object, we should *not* have 

1207 # gotten any keyword arguments that map to the request. 

1208 has_flattened_params = any([name, revision_id]) 

1209 if request is not None and has_flattened_params: 

1210 raise ValueError( 

1211 "If the `request` argument is set, then none of " 

1212 "the individual field arguments should be set." 

1213 ) 

1214 

1215 # Minor optimization to avoid making a copy if the user passes 

1216 # in a schema.DeleteSchemaRevisionRequest. 

1217 # There's no risk of modifying the input as we've already verified 

1218 # there are no flattened fields. 

1219 if not isinstance(request, schema.DeleteSchemaRevisionRequest): 

1220 request = schema.DeleteSchemaRevisionRequest(request) 

1221 # If we have keyword arguments corresponding to fields on the 

1222 # request, apply these. 

1223 if name is not None: 

1224 request.name = name 

1225 if revision_id is not None: 

1226 request.revision_id = revision_id 

1227 

1228 # Wrap the RPC method; this adds retry and timeout information, 

1229 # and friendly error handling. 

1230 rpc = self._transport._wrapped_methods[self._transport.delete_schema_revision] 

1231 

1232 # Certain fields should be provided within the metadata header; 

1233 # add these here. 

1234 metadata = tuple(metadata) + ( 

1235 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1236 ) 

1237 

1238 # Send the request. 

1239 response = rpc( 

1240 request, 

1241 retry=retry, 

1242 timeout=timeout, 

1243 metadata=metadata, 

1244 ) 

1245 

1246 # Done; return the response. 

1247 return response 

1248 

1249 def delete_schema( 

1250 self, 

1251 request: Optional[Union[schema.DeleteSchemaRequest, dict]] = None, 

1252 *, 

1253 name: Optional[str] = None, 

1254 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1255 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1256 metadata: Sequence[Tuple[str, str]] = (), 

1257 ) -> None: 

1258 r"""Deletes a schema. 

1259 

1260 .. code-block:: python 

1261 

1262 # This snippet has been automatically generated and should be regarded as a 

1263 # code template only. 

1264 # It will require modifications to work: 

1265 # - It may require correct/in-range values for request initialization. 

1266 # - It may require specifying regional endpoints when creating the service 

1267 # client as shown in: 

1268 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1269 from google import pubsub_v1 

1270 

1271 def sample_delete_schema(): 

1272 # Create a client 

1273 client = pubsub_v1.SchemaServiceClient() 

1274 

1275 # Initialize request argument(s) 

1276 request = pubsub_v1.DeleteSchemaRequest( 

1277 name="name_value", 

1278 ) 

1279 

1280 # Make the request 

1281 client.delete_schema(request=request) 

1282 

1283 Args: 

1284 request (Union[google.pubsub_v1.types.DeleteSchemaRequest, dict]): 

1285 The request object. Request for the `DeleteSchema` 

1286 method. 

1287 name (str): 

1288 Required. Name of the schema to delete. Format is 

1289 ``projects/{project}/schemas/{schema}``. 

1290 

1291 This corresponds to the ``name`` field 

1292 on the ``request`` instance; if ``request`` is provided, this 

1293 should not be set. 

1294 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1295 should be retried. 

1296 timeout (float): The timeout for this request. 

1297 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1298 sent along with the request as metadata. 

1299 """ 

1300 # Create or coerce a protobuf request object. 

1301 # Quick check: If we got a request object, we should *not* have 

1302 # gotten any keyword arguments that map to the request. 

1303 has_flattened_params = any([name]) 

1304 if request is not None and has_flattened_params: 

1305 raise ValueError( 

1306 "If the `request` argument is set, then none of " 

1307 "the individual field arguments should be set." 

1308 ) 

1309 

1310 # Minor optimization to avoid making a copy if the user passes 

1311 # in a schema.DeleteSchemaRequest. 

1312 # There's no risk of modifying the input as we've already verified 

1313 # there are no flattened fields. 

1314 if not isinstance(request, schema.DeleteSchemaRequest): 

1315 request = schema.DeleteSchemaRequest(request) 

1316 # If we have keyword arguments corresponding to fields on the 

1317 # request, apply these. 

1318 if name is not None: 

1319 request.name = name 

1320 

1321 # Wrap the RPC method; this adds retry and timeout information, 

1322 # and friendly error handling. 

1323 rpc = self._transport._wrapped_methods[self._transport.delete_schema] 

1324 

1325 # Certain fields should be provided within the metadata header; 

1326 # add these here. 

1327 metadata = tuple(metadata) + ( 

1328 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1329 ) 

1330 

1331 # Send the request. 

1332 rpc( 

1333 request, 

1334 retry=retry, 

1335 timeout=timeout, 

1336 metadata=metadata, 

1337 ) 

1338 

1339 def validate_schema( 

1340 self, 

1341 request: Optional[Union[gp_schema.ValidateSchemaRequest, dict]] = None, 

1342 *, 

1343 parent: Optional[str] = None, 

1344 schema: Optional[gp_schema.Schema] = None, 

1345 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1346 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1347 metadata: Sequence[Tuple[str, str]] = (), 

1348 ) -> gp_schema.ValidateSchemaResponse: 

1349 r"""Validates a schema. 

1350 

1351 .. code-block:: python 

1352 

1353 # This snippet has been automatically generated and should be regarded as a 

1354 # code template only. 

1355 # It will require modifications to work: 

1356 # - It may require correct/in-range values for request initialization. 

1357 # - It may require specifying regional endpoints when creating the service 

1358 # client as shown in: 

1359 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1360 from google import pubsub_v1 

1361 

1362 def sample_validate_schema(): 

1363 # Create a client 

1364 client = pubsub_v1.SchemaServiceClient() 

1365 

1366 # Initialize request argument(s) 

1367 schema = pubsub_v1.Schema() 

1368 schema.name = "name_value" 

1369 

1370 request = pubsub_v1.ValidateSchemaRequest( 

1371 parent="parent_value", 

1372 schema=schema, 

1373 ) 

1374 

1375 # Make the request 

1376 response = client.validate_schema(request=request) 

1377 

1378 # Handle the response 

1379 print(response) 

1380 

1381 Args: 

1382 request (Union[google.pubsub_v1.types.ValidateSchemaRequest, dict]): 

1383 The request object. Request for the `ValidateSchema` 

1384 method. 

1385 parent (str): 

1386 Required. The name of the project in which to validate 

1387 schemas. Format is ``projects/{project-id}``. 

1388 

1389 This corresponds to the ``parent`` field 

1390 on the ``request`` instance; if ``request`` is provided, this 

1391 should not be set. 

1392 schema (google.pubsub_v1.types.Schema): 

1393 Required. The schema object to 

1394 validate. 

1395 

1396 This corresponds to the ``schema`` field 

1397 on the ``request`` instance; if ``request`` is provided, this 

1398 should not be set. 

1399 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1400 should be retried. 

1401 timeout (float): The timeout for this request. 

1402 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1403 sent along with the request as metadata. 

1404 

1405 Returns: 

1406 google.pubsub_v1.types.ValidateSchemaResponse: 

1407 Response for the ValidateSchema method. 

1408 Empty for now. 

1409 

1410 """ 

1411 # Create or coerce a protobuf request object. 

1412 # Quick check: If we got a request object, we should *not* have 

1413 # gotten any keyword arguments that map to the request. 

1414 has_flattened_params = any([parent, schema]) 

1415 if request is not None and has_flattened_params: 

1416 raise ValueError( 

1417 "If the `request` argument is set, then none of " 

1418 "the individual field arguments should be set." 

1419 ) 

1420 

1421 # Minor optimization to avoid making a copy if the user passes 

1422 # in a gp_schema.ValidateSchemaRequest. 

1423 # There's no risk of modifying the input as we've already verified 

1424 # there are no flattened fields. 

1425 if not isinstance(request, gp_schema.ValidateSchemaRequest): 

1426 request = gp_schema.ValidateSchemaRequest(request) 

1427 # If we have keyword arguments corresponding to fields on the 

1428 # request, apply these. 

1429 if parent is not None: 

1430 request.parent = parent 

1431 if schema is not None: 

1432 request.schema = schema 

1433 

1434 # Wrap the RPC method; this adds retry and timeout information, 

1435 # and friendly error handling. 

1436 rpc = self._transport._wrapped_methods[self._transport.validate_schema] 

1437 

1438 # Certain fields should be provided within the metadata header; 

1439 # add these here. 

1440 metadata = tuple(metadata) + ( 

1441 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

1442 ) 

1443 

1444 # Send the request. 

1445 response = rpc( 

1446 request, 

1447 retry=retry, 

1448 timeout=timeout, 

1449 metadata=metadata, 

1450 ) 

1451 

1452 # Done; return the response. 

1453 return response 

1454 

1455 def validate_message( 

1456 self, 

1457 request: Optional[Union[schema.ValidateMessageRequest, dict]] = None, 

1458 *, 

1459 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1460 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1461 metadata: Sequence[Tuple[str, str]] = (), 

1462 ) -> schema.ValidateMessageResponse: 

1463 r"""Validates a message against a schema. 

1464 

1465 .. code-block:: python 

1466 

1467 # This snippet has been automatically generated and should be regarded as a 

1468 # code template only. 

1469 # It will require modifications to work: 

1470 # - It may require correct/in-range values for request initialization. 

1471 # - It may require specifying regional endpoints when creating the service 

1472 # client as shown in: 

1473 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

1474 from google import pubsub_v1 

1475 

1476 def sample_validate_message(): 

1477 # Create a client 

1478 client = pubsub_v1.SchemaServiceClient() 

1479 

1480 # Initialize request argument(s) 

1481 request = pubsub_v1.ValidateMessageRequest( 

1482 name="name_value", 

1483 parent="parent_value", 

1484 ) 

1485 

1486 # Make the request 

1487 response = client.validate_message(request=request) 

1488 

1489 # Handle the response 

1490 print(response) 

1491 

1492 Args: 

1493 request (Union[google.pubsub_v1.types.ValidateMessageRequest, dict]): 

1494 The request object. Request for the `ValidateMessage` 

1495 method. 

1496 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1497 should be retried. 

1498 timeout (float): The timeout for this request. 

1499 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1500 sent along with the request as metadata. 

1501 

1502 Returns: 

1503 google.pubsub_v1.types.ValidateMessageResponse: 

1504 Response for the ValidateMessage method. 

1505 Empty for now. 

1506 

1507 """ 

1508 # Create or coerce a protobuf request object. 

1509 # Minor optimization to avoid making a copy if the user passes 

1510 # in a schema.ValidateMessageRequest. 

1511 # There's no risk of modifying the input as we've already verified 

1512 # there are no flattened fields. 

1513 if not isinstance(request, schema.ValidateMessageRequest): 

1514 request = schema.ValidateMessageRequest(request) 

1515 

1516 # Wrap the RPC method; this adds retry and timeout information, 

1517 # and friendly error handling. 

1518 rpc = self._transport._wrapped_methods[self._transport.validate_message] 

1519 

1520 # Certain fields should be provided within the metadata header; 

1521 # add these here. 

1522 metadata = tuple(metadata) + ( 

1523 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

1524 ) 

1525 

1526 # Send the request. 

1527 response = rpc( 

1528 request, 

1529 retry=retry, 

1530 timeout=timeout, 

1531 metadata=metadata, 

1532 ) 

1533 

1534 # Done; return the response. 

1535 return response 

1536 

1537 def __enter__(self) -> "SchemaServiceClient": 

1538 return self 

1539 

1540 def __exit__(self, type, value, traceback): 

1541 """Releases underlying transport's resources. 

1542 

1543 .. warning:: 

1544 ONLY use as a context manager if the transport is NOT shared 

1545 with other clients! Exiting the with block will CLOSE the transport 

1546 and may cause errors in other clients! 

1547 """ 

1548 self.transport.close() 

1549 

1550 def set_iam_policy( 

1551 self, 

1552 request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, 

1553 *, 

1554 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1555 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1556 metadata: Sequence[Tuple[str, str]] = (), 

1557 ) -> policy_pb2.Policy: 

1558 r"""Sets the IAM access control policy on the specified function. 

1559 

1560 Replaces any existing policy. 

1561 

1562 Args: 

1563 request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): 

1564 The request object. Request message for `SetIamPolicy` 

1565 method. 

1566 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

1567 should be retried. 

1568 timeout (float): The timeout for this request. 

1569 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1570 sent along with the request as metadata. 

1571 Returns: 

1572 ~.policy_pb2.Policy: 

1573 Defines an Identity and Access Management (IAM) policy. 

1574 It is used to specify access control policies for Cloud 

1575 Platform resources. 

1576 A ``Policy`` is a collection of ``bindings``. A 

1577 ``binding`` binds one or more ``members`` to a single 

1578 ``role``. Members can be user accounts, service 

1579 accounts, Google groups, and domains (such as G Suite). 

1580 A ``role`` is a named list of permissions (defined by 

1581 IAM or configured by users). A ``binding`` can 

1582 optionally specify a ``condition``, which is a logic 

1583 expression that further constrains the role binding 

1584 based on attributes about the request and/or target 

1585 resource. 

1586 

1587 **JSON Example** 

1588 

1589 :: 

1590 

1591 { 

1592 "bindings": [ 

1593 { 

1594 "role": "roles/resourcemanager.organizationAdmin", 

1595 "members": [ 

1596 "user:mike@example.com", 

1597 "group:admins@example.com", 

1598 "domain:google.com", 

1599 "serviceAccount:my-project-id@appspot.gserviceaccount.com" 

1600 ] 

1601 }, 

1602 { 

1603 "role": "roles/resourcemanager.organizationViewer", 

1604 "members": ["user:eve@example.com"], 

1605 "condition": { 

1606 "title": "expirable access", 

1607 "description": "Does not grant access after Sep 2020", 

1608 "expression": "request.time < 

1609 timestamp('2020-10-01T00:00:00.000Z')", 

1610 } 

1611 } 

1612 ] 

1613 } 

1614 

1615 **YAML Example** 

1616 

1617 :: 

1618 

1619 bindings: 

1620 - members: 

1621 - user:mike@example.com 

1622 - group:admins@example.com 

1623 - domain:google.com 

1624 - serviceAccount:my-project-id@appspot.gserviceaccount.com 

1625 role: roles/resourcemanager.organizationAdmin 

1626 - members: 

1627 - user:eve@example.com 

1628 role: roles/resourcemanager.organizationViewer 

1629 condition: 

1630 title: expirable access 

1631 description: Does not grant access after Sep 2020 

1632 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') 

1633 

1634 For a description of IAM and its features, see the `IAM 

1635 developer's 

1636 guide <https://cloud.google.com/iam/docs>`__. 

1637 """ 

1638 # Create or coerce a protobuf request object. 

1639 

1640 # The request isn't a proto-plus wrapped type, 

1641 # so it must be constructed via keyword expansion. 

1642 if isinstance(request, dict): 

1643 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

1644 

1645 # Wrap the RPC method; this adds retry and timeout information, 

1646 # and friendly error handling. 

1647 rpc = gapic_v1.method.wrap_method( 

1648 self._transport.set_iam_policy, 

1649 default_timeout=None, 

1650 client_info=DEFAULT_CLIENT_INFO, 

1651 ) 

1652 

1653 # Certain fields should be provided within the metadata header; 

1654 # add these here. 

1655 metadata = tuple(metadata) + ( 

1656 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

1657 ) 

1658 

1659 # Send the request. 

1660 response = rpc( 

1661 request, 

1662 retry=retry, 

1663 timeout=timeout, 

1664 metadata=metadata, 

1665 ) 

1666 

1667 # Done; return the response. 

1668 return response 

1669 

1670 def get_iam_policy( 

1671 self, 

1672 request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, 

1673 *, 

1674 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1675 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1676 metadata: Sequence[Tuple[str, str]] = (), 

1677 ) -> policy_pb2.Policy: 

1678 r"""Gets the IAM access control policy for a function. 

1679 

1680 Returns an empty policy if the function exists and does not have a 

1681 policy set. 

1682 

1683 Args: 

1684 request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): 

1685 The request object. Request message for `GetIamPolicy` 

1686 method. 

1687 retry (google.api_core.retry.Retry): Designation of what errors, if 

1688 any, should be retried. 

1689 timeout (float): The timeout for this request. 

1690 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1691 sent along with the request as metadata. 

1692 Returns: 

1693 ~.policy_pb2.Policy: 

1694 Defines an Identity and Access Management (IAM) policy. 

1695 It is used to specify access control policies for Cloud 

1696 Platform resources. 

1697 A ``Policy`` is a collection of ``bindings``. A 

1698 ``binding`` binds one or more ``members`` to a single 

1699 ``role``. Members can be user accounts, service 

1700 accounts, Google groups, and domains (such as G Suite). 

1701 A ``role`` is a named list of permissions (defined by 

1702 IAM or configured by users). A ``binding`` can 

1703 optionally specify a ``condition``, which is a logic 

1704 expression that further constrains the role binding 

1705 based on attributes about the request and/or target 

1706 resource. 

1707 

1708 **JSON Example** 

1709 

1710 :: 

1711 

1712 { 

1713 "bindings": [ 

1714 { 

1715 "role": "roles/resourcemanager.organizationAdmin", 

1716 "members": [ 

1717 "user:mike@example.com", 

1718 "group:admins@example.com", 

1719 "domain:google.com", 

1720 "serviceAccount:my-project-id@appspot.gserviceaccount.com" 

1721 ] 

1722 }, 

1723 { 

1724 "role": "roles/resourcemanager.organizationViewer", 

1725 "members": ["user:eve@example.com"], 

1726 "condition": { 

1727 "title": "expirable access", 

1728 "description": "Does not grant access after Sep 2020", 

1729 "expression": "request.time < 

1730 timestamp('2020-10-01T00:00:00.000Z')", 

1731 } 

1732 } 

1733 ] 

1734 } 

1735 

1736 **YAML Example** 

1737 

1738 :: 

1739 

1740 bindings: 

1741 - members: 

1742 - user:mike@example.com 

1743 - group:admins@example.com 

1744 - domain:google.com 

1745 - serviceAccount:my-project-id@appspot.gserviceaccount.com 

1746 role: roles/resourcemanager.organizationAdmin 

1747 - members: 

1748 - user:eve@example.com 

1749 role: roles/resourcemanager.organizationViewer 

1750 condition: 

1751 title: expirable access 

1752 description: Does not grant access after Sep 2020 

1753 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') 

1754 

1755 For a description of IAM and its features, see the `IAM 

1756 developer's 

1757 guide <https://cloud.google.com/iam/docs>`__. 

1758 """ 

1759 # Create or coerce a protobuf request object. 

1760 

1761 # The request isn't a proto-plus wrapped type, 

1762 # so it must be constructed via keyword expansion. 

1763 if isinstance(request, dict): 

1764 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

1765 

1766 # Wrap the RPC method; this adds retry and timeout information, 

1767 # and friendly error handling. 

1768 rpc = gapic_v1.method.wrap_method( 

1769 self._transport.get_iam_policy, 

1770 default_timeout=None, 

1771 client_info=DEFAULT_CLIENT_INFO, 

1772 ) 

1773 

1774 # Certain fields should be provided within the metadata header; 

1775 # add these here. 

1776 metadata = tuple(metadata) + ( 

1777 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

1778 ) 

1779 

1780 # Send the request. 

1781 response = rpc( 

1782 request, 

1783 retry=retry, 

1784 timeout=timeout, 

1785 metadata=metadata, 

1786 ) 

1787 

1788 # Done; return the response. 

1789 return response 

1790 

1791 def test_iam_permissions( 

1792 self, 

1793 request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, 

1794 *, 

1795 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

1796 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

1797 metadata: Sequence[Tuple[str, str]] = (), 

1798 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

1799 r"""Tests the specified IAM permissions against the IAM access control 

1800 policy for a function. 

1801 

1802 If the function does not exist, this will return an empty set 

1803 of permissions, not a NOT_FOUND error. 

1804 

1805 Args: 

1806 request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): 

1807 The request object. Request message for 

1808 `TestIamPermissions` method. 

1809 retry (google.api_core.retry.Retry): Designation of what errors, 

1810 if any, should be retried. 

1811 timeout (float): The timeout for this request. 

1812 metadata (Sequence[Tuple[str, str]]): Strings which should be 

1813 sent along with the request as metadata. 

1814 Returns: 

1815 ~.iam_policy_pb2.TestIamPermissionsResponse: 

1816 Response message for ``TestIamPermissions`` method. 

1817 """ 

1818 # Create or coerce a protobuf request object. 

1819 

1820 # The request isn't a proto-plus wrapped type, 

1821 # so it must be constructed via keyword expansion. 

1822 if isinstance(request, dict): 

1823 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

1824 

1825 # Wrap the RPC method; this adds retry and timeout information, 

1826 # and friendly error handling. 

1827 rpc = gapic_v1.method.wrap_method( 

1828 self._transport.test_iam_permissions, 

1829 default_timeout=None, 

1830 client_info=DEFAULT_CLIENT_INFO, 

1831 ) 

1832 

1833 # Certain fields should be provided within the metadata header; 

1834 # add these here. 

1835 metadata = tuple(metadata) + ( 

1836 gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), 

1837 ) 

1838 

1839 # Send the request. 

1840 response = rpc( 

1841 request, 

1842 retry=retry, 

1843 timeout=timeout, 

1844 metadata=metadata, 

1845 ) 

1846 

1847 # Done; return the response. 

1848 return response 

1849 

1850 

1851DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

1852 client_library_version=package_version.__version__ 

1853) 

1854 

1855 

1856__all__ = ("SchemaServiceClient",)