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

312 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:03 +0000

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

2# Copyright 2022 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

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 

61from .transports.rest import SchemaServiceRestTransport 

62 

63 

64class SchemaServiceClientMeta(type): 

65 """Metaclass for the SchemaService client. 

66 

67 This provides class-level methods for building and retrieving 

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

69 objects. 

70 """ 

71 

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

73 _transport_registry["grpc"] = SchemaServiceGrpcTransport 

74 _transport_registry["grpc_asyncio"] = SchemaServiceGrpcAsyncIOTransport 

75 _transport_registry["rest"] = SchemaServiceRestTransport 

76 

77 def get_transport_class( 

78 cls, 

79 label: Optional[str] = None, 

80 ) -> Type[SchemaServiceTransport]: 

81 """Returns an appropriate transport class. 

82 

83 Args: 

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

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

86 

87 Returns: 

88 The transport class to use. 

89 """ 

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

91 if label: 

92 return cls._transport_registry[label] 

93 

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

95 # in the dictionary). 

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

97 

98 

99class SchemaServiceClient(metaclass=SchemaServiceClientMeta): 

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

101 

102 @staticmethod 

103 def _get_default_mtls_endpoint(api_endpoint): 

104 """Converts api endpoint to mTLS endpoint. 

105 

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

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

108 Args: 

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

110 Returns: 

111 str: converted mTLS api endpoint. 

112 """ 

113 if not api_endpoint: 

114 return api_endpoint 

115 

116 mtls_endpoint_re = re.compile( 

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

118 ) 

119 

120 m = mtls_endpoint_re.match(api_endpoint) 

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

122 if mtls or not googledomain: 

123 return api_endpoint 

124 

125 if sandbox: 

126 return api_endpoint.replace( 

127 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" 

128 ) 

129 

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

131 

132 DEFAULT_ENDPOINT = "pubsub.googleapis.com" 

133 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore 

134 DEFAULT_ENDPOINT 

135 ) 

136 

137 @classmethod 

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

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

140 info. 

141 

142 Args: 

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

144 args: Additional arguments to pass to the constructor. 

145 kwargs: Additional arguments to pass to the constructor. 

146 

147 Returns: 

148 SchemaServiceClient: The constructed client. 

149 """ 

150 credentials = service_account.Credentials.from_service_account_info(info) 

151 kwargs["credentials"] = credentials 

152 return cls(*args, **kwargs) 

153 

154 @classmethod 

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

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

157 file. 

158 

159 Args: 

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

161 file. 

162 args: Additional arguments to pass to the constructor. 

163 kwargs: Additional arguments to pass to the constructor. 

164 

165 Returns: 

166 SchemaServiceClient: The constructed client. 

167 """ 

168 credentials = service_account.Credentials.from_service_account_file(filename) 

169 kwargs["credentials"] = credentials 

170 return cls(*args, **kwargs) 

171 

172 from_service_account_json = from_service_account_file 

173 

174 @property 

175 def transport(self) -> SchemaServiceTransport: 

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

177 

178 Returns: 

179 SchemaServiceTransport: The transport used by the client 

180 instance. 

181 """ 

182 return self._transport 

183 

184 @staticmethod 

185 def schema_path( 

186 project: str, 

187 schema: str, 

188 ) -> str: 

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

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

191 project=project, 

192 schema=schema, 

193 ) 

194 

195 @staticmethod 

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

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

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

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

200 

201 @staticmethod 

202 def common_billing_account_path( 

203 billing_account: str, 

204 ) -> str: 

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

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

207 billing_account=billing_account, 

208 ) 

209 

210 @staticmethod 

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

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

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

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

215 

216 @staticmethod 

217 def common_folder_path( 

218 folder: str, 

219 ) -> str: 

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

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

222 folder=folder, 

223 ) 

224 

225 @staticmethod 

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

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

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

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

230 

231 @staticmethod 

232 def common_organization_path( 

233 organization: str, 

234 ) -> str: 

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

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

237 organization=organization, 

238 ) 

239 

240 @staticmethod 

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

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

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

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

245 

246 @staticmethod 

247 def common_project_path( 

248 project: str, 

249 ) -> str: 

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

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

252 project=project, 

253 ) 

254 

255 @staticmethod 

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

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

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

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

260 

261 @staticmethod 

262 def common_location_path( 

263 project: str, 

264 location: str, 

265 ) -> str: 

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

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

268 project=project, 

269 location=location, 

270 ) 

271 

272 @staticmethod 

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

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

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

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

277 

278 @classmethod 

279 def get_mtls_endpoint_and_cert_source( 

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

281 ): 

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

283 

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

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

286 client cert source is None. 

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

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

289 source is None. 

290 

291 The API endpoint is determined in the following order: 

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

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

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

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

296 use the default API endpoint. 

297 

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

299 

300 Args: 

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

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

303 in this method. 

304 

305 Returns: 

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

307 client cert source to use. 

308 

309 Raises: 

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

311 """ 

312 if client_options is None: 

313 client_options = client_options_lib.ClientOptions() 

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

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

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

317 raise ValueError( 

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

319 ) 

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

321 raise MutualTLSChannelError( 

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

323 ) 

324 

325 # Figure out the client cert source to use. 

326 client_cert_source = None 

327 if use_client_cert == "true": 

328 if client_options.client_cert_source: 

329 client_cert_source = client_options.client_cert_source 

330 elif mtls.has_default_client_cert_source(): 

331 client_cert_source = mtls.default_client_cert_source() 

332 

333 # Figure out which api endpoint to use. 

334 if client_options.api_endpoint is not None: 

335 api_endpoint = client_options.api_endpoint 

336 elif use_mtls_endpoint == "always" or ( 

337 use_mtls_endpoint == "auto" and client_cert_source 

338 ): 

339 api_endpoint = cls.DEFAULT_MTLS_ENDPOINT 

340 else: 

341 api_endpoint = cls.DEFAULT_ENDPOINT 

342 

343 return api_endpoint, client_cert_source 

344 

345 def __init__( 

346 self, 

347 *, 

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

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

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

351 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

352 ) -> None: 

353 """Instantiates the schema service client. 

354 

355 Args: 

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

357 authorization credentials to attach to requests. These 

358 credentials identify the application to the service; if none 

359 are specified, the client will attempt to ascertain the 

360 credentials from the environment. 

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

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

363 automatically. 

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

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

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

367 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 

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

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

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

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

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

373 precedence if provided. 

374 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

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

376 to provide client certificate for mutual TLS transport. If 

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

378 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

379 set, no client certificate will be used. 

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

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

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

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

384 your own client library. 

385 

386 Raises: 

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

388 creation failed for any reason. 

389 """ 

390 if isinstance(client_options, dict): 

391 client_options = client_options_lib.from_dict(client_options) 

392 if client_options is None: 

393 client_options = client_options_lib.ClientOptions() 

394 client_options = cast(client_options_lib.ClientOptions, client_options) 

395 

396 api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( 

397 client_options 

398 ) 

399 

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

401 if api_key_value and credentials: 

402 raise ValueError( 

403 "client_options.api_key and credentials are mutually exclusive" 

404 ) 

405 

406 # Save or instantiate the transport. 

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

408 # instance provides an extensibility point for unusual situations. 

409 if isinstance(transport, SchemaServiceTransport): 

410 # transport is a SchemaServiceTransport instance. 

411 if credentials or client_options.credentials_file or api_key_value: 

412 raise ValueError( 

413 "When providing a transport instance, " 

414 "provide its credentials directly." 

415 ) 

416 if client_options.scopes: 

417 raise ValueError( 

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

419 "directly." 

420 ) 

421 self._transport = transport 

422 else: 

423 import google.auth._default # type: ignore 

424 

425 if api_key_value and hasattr( 

426 google.auth._default, "get_api_key_credentials" 

427 ): 

428 credentials = google.auth._default.get_api_key_credentials( 

429 api_key_value 

430 ) 

431 

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

433 

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

435 if emulator_host: 

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

437 channel = grpc.insecure_channel(target=emulator_host) 

438 else: 

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

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

441 

442 self._transport = Transport( 

443 credentials=credentials, 

444 credentials_file=client_options.credentials_file, 

445 host=api_endpoint, 

446 scopes=client_options.scopes, 

447 client_cert_source_for_mtls=client_cert_source_func, 

448 quota_project_id=client_options.quota_project_id, 

449 client_info=client_info, 

450 always_use_jwt_access=True, 

451 api_audience=client_options.api_audience, 

452 ) 

453 

454 def create_schema( 

455 self, 

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

457 *, 

458 parent: Optional[str] = None, 

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

460 schema_id: Optional[str] = None, 

461 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

464 ) -> gp_schema.Schema: 

465 r"""Creates a schema. 

466 

467 .. code-block:: python 

468 

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

470 # code template only. 

471 # It will require modifications to work: 

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

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

474 # client as shown in: 

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

476 from google import pubsub_v1 

477 

478 def sample_create_schema(): 

479 # Create a client 

480 client = pubsub_v1.SchemaServiceClient() 

481 

482 # Initialize request argument(s) 

483 schema = pubsub_v1.Schema() 

484 schema.name = "name_value" 

485 

486 request = pubsub_v1.CreateSchemaRequest( 

487 parent="parent_value", 

488 schema=schema, 

489 ) 

490 

491 # Make the request 

492 response = client.create_schema(request=request) 

493 

494 # Handle the response 

495 print(response) 

496 

497 Args: 

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

499 The request object. Request for the CreateSchema method. 

500 parent (str): 

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

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

503 

504 This corresponds to the ``parent`` field 

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

506 should not be set. 

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

508 Required. The schema object to create. 

509 

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

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

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

513 

514 This corresponds to the ``schema`` field 

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

516 should not be set. 

517 schema_id (str): 

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

519 final component of the schema's resource name. 

520 

521 See 

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

523 for resource name constraints. 

524 

525 This corresponds to the ``schema_id`` field 

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

527 should not be set. 

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

529 should be retried. 

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

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

532 sent along with the request as metadata. 

533 

534 Returns: 

535 google.pubsub_v1.types.Schema: 

536 A schema resource. 

537 """ 

538 # Create or coerce a protobuf request object. 

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

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

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

542 if request is not None and has_flattened_params: 

543 raise ValueError( 

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

545 "the individual field arguments should be set." 

546 ) 

547 

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

549 # in a gp_schema.CreateSchemaRequest. 

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

551 # there are no flattened fields. 

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

553 request = gp_schema.CreateSchemaRequest(request) 

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

555 # request, apply these. 

556 if parent is not None: 

557 request.parent = parent 

558 if schema is not None: 

559 request.schema = schema 

560 if schema_id is not None: 

561 request.schema_id = schema_id 

562 

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

564 # and friendly error handling. 

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

566 

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

568 # add these here. 

569 metadata = tuple(metadata) + ( 

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

571 ) 

572 

573 # Send the request. 

574 response = rpc( 

575 request, 

576 retry=retry, 

577 timeout=timeout, 

578 metadata=metadata, 

579 ) 

580 

581 # Done; return the response. 

582 return response 

583 

584 def get_schema( 

585 self, 

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

587 *, 

588 name: Optional[str] = None, 

589 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

592 ) -> schema.Schema: 

593 r"""Gets a schema. 

594 

595 .. code-block:: python 

596 

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

598 # code template only. 

599 # It will require modifications to work: 

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

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

602 # client as shown in: 

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

604 from google import pubsub_v1 

605 

606 def sample_get_schema(): 

607 # Create a client 

608 client = pubsub_v1.SchemaServiceClient() 

609 

610 # Initialize request argument(s) 

611 request = pubsub_v1.GetSchemaRequest( 

612 name="name_value", 

613 ) 

614 

615 # Make the request 

616 response = client.get_schema(request=request) 

617 

618 # Handle the response 

619 print(response) 

620 

621 Args: 

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

623 The request object. Request for the GetSchema method. 

624 name (str): 

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

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

627 

628 This corresponds to the ``name`` field 

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

630 should not be set. 

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

632 should be retried. 

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

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

635 sent along with the request as metadata. 

636 

637 Returns: 

638 google.pubsub_v1.types.Schema: 

639 A schema resource. 

640 """ 

641 # Create or coerce a protobuf request object. 

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

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

644 has_flattened_params = any([name]) 

645 if request is not None and has_flattened_params: 

646 raise ValueError( 

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

648 "the individual field arguments should be set." 

649 ) 

650 

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

652 # in a schema.GetSchemaRequest. 

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

654 # there are no flattened fields. 

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

656 request = schema.GetSchemaRequest(request) 

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

658 # request, apply these. 

659 if name is not None: 

660 request.name = name 

661 

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

663 # and friendly error handling. 

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

665 

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

667 # add these here. 

668 metadata = tuple(metadata) + ( 

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

670 ) 

671 

672 # Send the request. 

673 response = rpc( 

674 request, 

675 retry=retry, 

676 timeout=timeout, 

677 metadata=metadata, 

678 ) 

679 

680 # Done; return the response. 

681 return response 

682 

683 def list_schemas( 

684 self, 

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

686 *, 

687 parent: Optional[str] = None, 

688 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

691 ) -> pagers.ListSchemasPager: 

692 r"""Lists schemas in a project. 

693 

694 .. code-block:: python 

695 

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

697 # code template only. 

698 # It will require modifications to work: 

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

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

701 # client as shown in: 

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

703 from google import pubsub_v1 

704 

705 def sample_list_schemas(): 

706 # Create a client 

707 client = pubsub_v1.SchemaServiceClient() 

708 

709 # Initialize request argument(s) 

710 request = pubsub_v1.ListSchemasRequest( 

711 parent="parent_value", 

712 ) 

713 

714 # Make the request 

715 page_result = client.list_schemas(request=request) 

716 

717 # Handle the response 

718 for response in page_result: 

719 print(response) 

720 

721 Args: 

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

723 The request object. Request for the ``ListSchemas`` method. 

724 parent (str): 

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

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

727 

728 This corresponds to the ``parent`` field 

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

730 should not be set. 

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

732 should be retried. 

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

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

735 sent along with the request as metadata. 

736 

737 Returns: 

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

739 Response for the ListSchemas method. 

740 

741 Iterating over this object will yield results and 

742 resolve additional pages automatically. 

743 

744 """ 

745 # Create or coerce a protobuf request object. 

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

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

748 has_flattened_params = any([parent]) 

749 if request is not None and has_flattened_params: 

750 raise ValueError( 

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

752 "the individual field arguments should be set." 

753 ) 

754 

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

756 # in a schema.ListSchemasRequest. 

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

758 # there are no flattened fields. 

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

760 request = schema.ListSchemasRequest(request) 

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

762 # request, apply these. 

763 if parent is not None: 

764 request.parent = parent 

765 

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

767 # and friendly error handling. 

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

769 

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

771 # add these here. 

772 metadata = tuple(metadata) + ( 

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

774 ) 

775 

776 # Send the request. 

777 response = rpc( 

778 request, 

779 retry=retry, 

780 timeout=timeout, 

781 metadata=metadata, 

782 ) 

783 

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

785 # an `__iter__` convenience method. 

786 response = pagers.ListSchemasPager( 

787 method=rpc, 

788 request=request, 

789 response=response, 

790 metadata=metadata, 

791 ) 

792 

793 # Done; return the response. 

794 return response 

795 

796 def list_schema_revisions( 

797 self, 

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

799 *, 

800 name: Optional[str] = None, 

801 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

804 ) -> pagers.ListSchemaRevisionsPager: 

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

806 

807 .. code-block:: python 

808 

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

810 # code template only. 

811 # It will require modifications to work: 

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

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

814 # client as shown in: 

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

816 from google import pubsub_v1 

817 

818 def sample_list_schema_revisions(): 

819 # Create a client 

820 client = pubsub_v1.SchemaServiceClient() 

821 

822 # Initialize request argument(s) 

823 request = pubsub_v1.ListSchemaRevisionsRequest( 

824 name="name_value", 

825 ) 

826 

827 # Make the request 

828 page_result = client.list_schema_revisions(request=request) 

829 

830 # Handle the response 

831 for response in page_result: 

832 print(response) 

833 

834 Args: 

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

836 The request object. Request for the ``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`` method. 

1065 name (str): 

1066 Required. The schema being rolled 

1067 back with revision id. 

1068 

1069 This corresponds to the ``name`` field 

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

1071 should not be set. 

1072 revision_id (str): 

1073 Required. The revision ID to roll 

1074 back to. It must be a revision of the 

1075 same schema. 

1076 Example: c7cfa2a8 

1077 

1078 This corresponds to the ``revision_id`` field 

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

1080 should not be set. 

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

1082 should be retried. 

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

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

1085 sent along with the request as metadata. 

1086 

1087 Returns: 

1088 google.pubsub_v1.types.Schema: 

1089 A schema resource. 

1090 """ 

1091 # Create or coerce a protobuf request object. 

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

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

1094 has_flattened_params = any([name, revision_id]) 

1095 if request is not None and has_flattened_params: 

1096 raise ValueError( 

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

1098 "the individual field arguments should be set." 

1099 ) 

1100 

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

1102 # in a schema.RollbackSchemaRequest. 

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

1104 # there are no flattened fields. 

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

1106 request = schema.RollbackSchemaRequest(request) 

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

1108 # request, apply these. 

1109 if name is not None: 

1110 request.name = name 

1111 if revision_id is not None: 

1112 request.revision_id = revision_id 

1113 

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

1115 # and friendly error handling. 

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

1117 

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

1119 # add these here. 

1120 metadata = tuple(metadata) + ( 

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

1122 ) 

1123 

1124 # Send the request. 

1125 response = rpc( 

1126 request, 

1127 retry=retry, 

1128 timeout=timeout, 

1129 metadata=metadata, 

1130 ) 

1131 

1132 # Done; return the response. 

1133 return response 

1134 

1135 def delete_schema_revision( 

1136 self, 

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

1138 *, 

1139 name: Optional[str] = None, 

1140 revision_id: Optional[str] = None, 

1141 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1144 ) -> schema.Schema: 

1145 r"""Deletes a specific schema revision. 

1146 

1147 .. code-block:: python 

1148 

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

1150 # code template only. 

1151 # It will require modifications to work: 

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

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

1154 # client as shown in: 

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

1156 from google import pubsub_v1 

1157 

1158 def sample_delete_schema_revision(): 

1159 # Create a client 

1160 client = pubsub_v1.SchemaServiceClient() 

1161 

1162 # Initialize request argument(s) 

1163 request = pubsub_v1.DeleteSchemaRevisionRequest( 

1164 name="name_value", 

1165 ) 

1166 

1167 # Make the request 

1168 response = client.delete_schema_revision(request=request) 

1169 

1170 # Handle the response 

1171 print(response) 

1172 

1173 Args: 

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

1175 The request object. Request for the ``DeleteSchemaRevision`` method. 

1176 name (str): 

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

1178 with a revision ID explicitly included. 

1179 

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

1181 

1182 This corresponds to the ``name`` field 

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

1184 should not be set. 

1185 revision_id (str): 

1186 Optional. This field is deprecated and should not be 

1187 used for specifying the revision ID. The revision ID 

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

1189 

1190 This corresponds to the ``revision_id`` field 

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

1192 should not be set. 

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

1194 should be retried. 

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

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

1197 sent along with the request as metadata. 

1198 

1199 Returns: 

1200 google.pubsub_v1.types.Schema: 

1201 A schema resource. 

1202 """ 

1203 # Create or coerce a protobuf request object. 

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

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

1206 has_flattened_params = any([name, revision_id]) 

1207 if request is not None and has_flattened_params: 

1208 raise ValueError( 

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

1210 "the individual field arguments should be set." 

1211 ) 

1212 

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

1214 # in a schema.DeleteSchemaRevisionRequest. 

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

1216 # there are no flattened fields. 

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

1218 request = schema.DeleteSchemaRevisionRequest(request) 

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

1220 # request, apply these. 

1221 if name is not None: 

1222 request.name = name 

1223 if revision_id is not None: 

1224 request.revision_id = revision_id 

1225 

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

1227 # and friendly error handling. 

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

1229 

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

1231 # add these here. 

1232 metadata = tuple(metadata) + ( 

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

1234 ) 

1235 

1236 # Send the request. 

1237 response = rpc( 

1238 request, 

1239 retry=retry, 

1240 timeout=timeout, 

1241 metadata=metadata, 

1242 ) 

1243 

1244 # Done; return the response. 

1245 return response 

1246 

1247 def delete_schema( 

1248 self, 

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

1250 *, 

1251 name: Optional[str] = None, 

1252 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1255 ) -> None: 

1256 r"""Deletes a schema. 

1257 

1258 .. code-block:: python 

1259 

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

1261 # code template only. 

1262 # It will require modifications to work: 

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

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

1265 # client as shown in: 

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

1267 from google import pubsub_v1 

1268 

1269 def sample_delete_schema(): 

1270 # Create a client 

1271 client = pubsub_v1.SchemaServiceClient() 

1272 

1273 # Initialize request argument(s) 

1274 request = pubsub_v1.DeleteSchemaRequest( 

1275 name="name_value", 

1276 ) 

1277 

1278 # Make the request 

1279 client.delete_schema(request=request) 

1280 

1281 Args: 

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

1283 The request object. Request for the ``DeleteSchema`` method. 

1284 name (str): 

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

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

1287 

1288 This corresponds to the ``name`` field 

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

1290 should not be set. 

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

1292 should be retried. 

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

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

1295 sent along with the request as metadata. 

1296 """ 

1297 # Create or coerce a protobuf request object. 

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

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

1300 has_flattened_params = any([name]) 

1301 if request is not None and has_flattened_params: 

1302 raise ValueError( 

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

1304 "the individual field arguments should be set." 

1305 ) 

1306 

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

1308 # in a schema.DeleteSchemaRequest. 

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

1310 # there are no flattened fields. 

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

1312 request = schema.DeleteSchemaRequest(request) 

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

1314 # request, apply these. 

1315 if name is not None: 

1316 request.name = name 

1317 

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

1319 # and friendly error handling. 

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

1321 

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

1323 # add these here. 

1324 metadata = tuple(metadata) + ( 

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

1326 ) 

1327 

1328 # Send the request. 

1329 rpc( 

1330 request, 

1331 retry=retry, 

1332 timeout=timeout, 

1333 metadata=metadata, 

1334 ) 

1335 

1336 def validate_schema( 

1337 self, 

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

1339 *, 

1340 parent: Optional[str] = None, 

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

1342 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1345 ) -> gp_schema.ValidateSchemaResponse: 

1346 r"""Validates a schema. 

1347 

1348 .. code-block:: python 

1349 

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

1351 # code template only. 

1352 # It will require modifications to work: 

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

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

1355 # client as shown in: 

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

1357 from google import pubsub_v1 

1358 

1359 def sample_validate_schema(): 

1360 # Create a client 

1361 client = pubsub_v1.SchemaServiceClient() 

1362 

1363 # Initialize request argument(s) 

1364 schema = pubsub_v1.Schema() 

1365 schema.name = "name_value" 

1366 

1367 request = pubsub_v1.ValidateSchemaRequest( 

1368 parent="parent_value", 

1369 schema=schema, 

1370 ) 

1371 

1372 # Make the request 

1373 response = client.validate_schema(request=request) 

1374 

1375 # Handle the response 

1376 print(response) 

1377 

1378 Args: 

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

1380 The request object. Request for the ``ValidateSchema`` method. 

1381 parent (str): 

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

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

1384 

1385 This corresponds to the ``parent`` field 

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

1387 should not be set. 

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

1389 Required. The schema object to 

1390 validate. 

1391 

1392 This corresponds to the ``schema`` field 

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

1394 should not be set. 

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

1396 should be retried. 

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

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

1399 sent along with the request as metadata. 

1400 

1401 Returns: 

1402 google.pubsub_v1.types.ValidateSchemaResponse: 

1403 Response for the ValidateSchema method. 

1404 Empty for now. 

1405 

1406 """ 

1407 # Create or coerce a protobuf request object. 

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

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

1410 has_flattened_params = any([parent, schema]) 

1411 if request is not None and has_flattened_params: 

1412 raise ValueError( 

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

1414 "the individual field arguments should be set." 

1415 ) 

1416 

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

1418 # in a gp_schema.ValidateSchemaRequest. 

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

1420 # there are no flattened fields. 

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

1422 request = gp_schema.ValidateSchemaRequest(request) 

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

1424 # request, apply these. 

1425 if parent is not None: 

1426 request.parent = parent 

1427 if schema is not None: 

1428 request.schema = schema 

1429 

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

1431 # and friendly error handling. 

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

1433 

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

1435 # add these here. 

1436 metadata = tuple(metadata) + ( 

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

1438 ) 

1439 

1440 # Send the request. 

1441 response = rpc( 

1442 request, 

1443 retry=retry, 

1444 timeout=timeout, 

1445 metadata=metadata, 

1446 ) 

1447 

1448 # Done; return the response. 

1449 return response 

1450 

1451 def validate_message( 

1452 self, 

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

1454 *, 

1455 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1458 ) -> schema.ValidateMessageResponse: 

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

1460 

1461 .. code-block:: python 

1462 

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

1464 # code template only. 

1465 # It will require modifications to work: 

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

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

1468 # client as shown in: 

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

1470 from google import pubsub_v1 

1471 

1472 def sample_validate_message(): 

1473 # Create a client 

1474 client = pubsub_v1.SchemaServiceClient() 

1475 

1476 # Initialize request argument(s) 

1477 request = pubsub_v1.ValidateMessageRequest( 

1478 name="name_value", 

1479 parent="parent_value", 

1480 ) 

1481 

1482 # Make the request 

1483 response = client.validate_message(request=request) 

1484 

1485 # Handle the response 

1486 print(response) 

1487 

1488 Args: 

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

1490 The request object. Request for the ``ValidateMessage`` method. 

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

1492 should be retried. 

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

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

1495 sent along with the request as metadata. 

1496 

1497 Returns: 

1498 google.pubsub_v1.types.ValidateMessageResponse: 

1499 Response for the ValidateMessage method. 

1500 Empty for now. 

1501 

1502 """ 

1503 # Create or coerce a protobuf request object. 

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

1505 # in a schema.ValidateMessageRequest. 

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

1507 # there are no flattened fields. 

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

1509 request = schema.ValidateMessageRequest(request) 

1510 

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

1512 # and friendly error handling. 

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

1514 

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

1516 # add these here. 

1517 metadata = tuple(metadata) + ( 

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

1519 ) 

1520 

1521 # Send the request. 

1522 response = rpc( 

1523 request, 

1524 retry=retry, 

1525 timeout=timeout, 

1526 metadata=metadata, 

1527 ) 

1528 

1529 # Done; return the response. 

1530 return response 

1531 

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

1533 return self 

1534 

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

1536 """Releases underlying transport's resources. 

1537 

1538 .. warning:: 

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

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

1541 and may cause errors in other clients! 

1542 """ 

1543 self.transport.close() 

1544 

1545 def set_iam_policy( 

1546 self, 

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

1548 *, 

1549 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1552 ) -> policy_pb2.Policy: 

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

1554 

1555 Replaces any existing policy. 

1556 

1557 Args: 

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

1559 The request object. Request message for `SetIamPolicy` 

1560 method. 

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

1562 should be retried. 

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

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

1565 sent along with the request as metadata. 

1566 Returns: 

1567 ~.policy_pb2.Policy: 

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

1569 It is used to specify access control policies for Cloud 

1570 Platform resources. 

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

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

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

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

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

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

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

1578 expression that further constrains the role binding 

1579 based on attributes about the request and/or target 

1580 resource. 

1581 

1582 **JSON Example** 

1583 

1584 :: 

1585 

1586 { 

1587 "bindings": [ 

1588 { 

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

1590 "members": [ 

1591 "user:mike@example.com", 

1592 "group:admins@example.com", 

1593 "domain:google.com", 

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

1595 ] 

1596 }, 

1597 { 

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

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

1600 "condition": { 

1601 "title": "expirable access", 

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

1603 "expression": "request.time < 

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

1605 } 

1606 } 

1607 ] 

1608 } 

1609 

1610 **YAML Example** 

1611 

1612 :: 

1613 

1614 bindings: 

1615 - members: 

1616 - user:mike@example.com 

1617 - group:admins@example.com 

1618 - domain:google.com 

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

1620 role: roles/resourcemanager.organizationAdmin 

1621 - members: 

1622 - user:eve@example.com 

1623 role: roles/resourcemanager.organizationViewer 

1624 condition: 

1625 title: expirable access 

1626 description: Does not grant access after Sep 2020 

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

1628 

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

1630 developer's 

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

1632 """ 

1633 # Create or coerce a protobuf request object. 

1634 

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

1636 # so it must be constructed via keyword expansion. 

1637 if isinstance(request, dict): 

1638 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

1639 

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

1641 # and friendly error handling. 

1642 rpc = gapic_v1.method.wrap_method( 

1643 self._transport.set_iam_policy, 

1644 default_timeout=None, 

1645 client_info=DEFAULT_CLIENT_INFO, 

1646 ) 

1647 

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

1649 # add these here. 

1650 metadata = tuple(metadata) + ( 

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

1652 ) 

1653 

1654 # Send the request. 

1655 response = rpc( 

1656 request, 

1657 retry=retry, 

1658 timeout=timeout, 

1659 metadata=metadata, 

1660 ) 

1661 

1662 # Done; return the response. 

1663 return response 

1664 

1665 def get_iam_policy( 

1666 self, 

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

1668 *, 

1669 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1672 ) -> policy_pb2.Policy: 

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

1674 

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

1676 policy set. 

1677 

1678 Args: 

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

1680 The request object. Request message for `GetIamPolicy` 

1681 method. 

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

1683 any, should be retried. 

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

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

1686 sent along with the request as metadata. 

1687 Returns: 

1688 ~.policy_pb2.Policy: 

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

1690 It is used to specify access control policies for Cloud 

1691 Platform resources. 

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

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

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

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

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

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

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

1699 expression that further constrains the role binding 

1700 based on attributes about the request and/or target 

1701 resource. 

1702 

1703 **JSON Example** 

1704 

1705 :: 

1706 

1707 { 

1708 "bindings": [ 

1709 { 

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

1711 "members": [ 

1712 "user:mike@example.com", 

1713 "group:admins@example.com", 

1714 "domain:google.com", 

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

1716 ] 

1717 }, 

1718 { 

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

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

1721 "condition": { 

1722 "title": "expirable access", 

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

1724 "expression": "request.time < 

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

1726 } 

1727 } 

1728 ] 

1729 } 

1730 

1731 **YAML Example** 

1732 

1733 :: 

1734 

1735 bindings: 

1736 - members: 

1737 - user:mike@example.com 

1738 - group:admins@example.com 

1739 - domain:google.com 

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

1741 role: roles/resourcemanager.organizationAdmin 

1742 - members: 

1743 - user:eve@example.com 

1744 role: roles/resourcemanager.organizationViewer 

1745 condition: 

1746 title: expirable access 

1747 description: Does not grant access after Sep 2020 

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

1749 

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

1751 developer's 

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

1753 """ 

1754 # Create or coerce a protobuf request object. 

1755 

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

1757 # so it must be constructed via keyword expansion. 

1758 if isinstance(request, dict): 

1759 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

1760 

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

1762 # and friendly error handling. 

1763 rpc = gapic_v1.method.wrap_method( 

1764 self._transport.get_iam_policy, 

1765 default_timeout=None, 

1766 client_info=DEFAULT_CLIENT_INFO, 

1767 ) 

1768 

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

1770 # add these here. 

1771 metadata = tuple(metadata) + ( 

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

1773 ) 

1774 

1775 # Send the request. 

1776 response = rpc( 

1777 request, 

1778 retry=retry, 

1779 timeout=timeout, 

1780 metadata=metadata, 

1781 ) 

1782 

1783 # Done; return the response. 

1784 return response 

1785 

1786 def test_iam_permissions( 

1787 self, 

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

1789 *, 

1790 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1793 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

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

1795 policy for a function. 

1796 

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

1798 of permissions, not a NOT_FOUND error. 

1799 

1800 Args: 

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

1802 The request object. Request message for 

1803 `TestIamPermissions` method. 

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

1805 if any, should be retried. 

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

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

1808 sent along with the request as metadata. 

1809 Returns: 

1810 ~.iam_policy_pb2.TestIamPermissionsResponse: 

1811 Response message for ``TestIamPermissions`` method. 

1812 """ 

1813 # Create or coerce a protobuf request object. 

1814 

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

1816 # so it must be constructed via keyword expansion. 

1817 if isinstance(request, dict): 

1818 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

1819 

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

1821 # and friendly error handling. 

1822 rpc = gapic_v1.method.wrap_method( 

1823 self._transport.test_iam_permissions, 

1824 default_timeout=None, 

1825 client_info=DEFAULT_CLIENT_INFO, 

1826 ) 

1827 

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

1829 # add these here. 

1830 metadata = tuple(metadata) + ( 

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

1832 ) 

1833 

1834 # Send the request. 

1835 response = rpc( 

1836 request, 

1837 retry=retry, 

1838 timeout=timeout, 

1839 metadata=metadata, 

1840 ) 

1841 

1842 # Done; return the response. 

1843 return response 

1844 

1845 

1846DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

1847 client_library_version=package_version.__version__ 

1848) 

1849 

1850 

1851__all__ = ("SchemaServiceClient",)