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

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

424 statements  

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

2# Copyright 2025 Google LLC 

3# 

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

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

6# You may obtain a copy of the License at 

7# 

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

9# 

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

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

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

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

14# limitations under the License. 

15# 

16from collections import OrderedDict 

17from http import HTTPStatus 

18import json 

19import logging as std_logging 

20import functools 

21import os 

22import re 

23from typing import ( 

24 Dict, 

25 Callable, 

26 Mapping, 

27 MutableMapping, 

28 MutableSequence, 

29 Optional, 

30 Sequence, 

31 Tuple, 

32 Type, 

33 Union, 

34 cast, 

35) 

36import warnings 

37 

38from google.pubsub_v1 import gapic_version as package_version 

39 

40from google.api_core import client_options as client_options_lib 

41from google.api_core import exceptions as core_exceptions 

42from google.api_core import gapic_v1 

43from google.api_core import retry as retries 

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

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

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

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

48from google.oauth2 import service_account # type: ignore 

49import google.protobuf 

50 

51try: 

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

53except AttributeError: # pragma: NO COVER 

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

55 

56try: 

57 from google.api_core import client_logging # type: ignore 

58 

59 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

60except ImportError: # pragma: NO COVER 

61 CLIENT_LOGGING_SUPPORTED = False 

62 

63_LOGGER = std_logging.getLogger(__name__) 

64 

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

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

67from google.protobuf import timestamp_pb2 # type: ignore 

68from google.pubsub_v1.services.schema_service import pagers 

69from google.pubsub_v1.types import schema 

70from google.pubsub_v1.types import schema as gp_schema 

71 

72import grpc 

73from .transports.base import SchemaServiceTransport, DEFAULT_CLIENT_INFO 

74from .transports.grpc import SchemaServiceGrpcTransport 

75from .transports.grpc_asyncio import SchemaServiceGrpcAsyncIOTransport 

76from .transports.rest import SchemaServiceRestTransport 

77 

78 

79class SchemaServiceClientMeta(type): 

80 """Metaclass for the SchemaService client. 

81 

82 This provides class-level methods for building and retrieving 

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

84 objects. 

85 """ 

86 

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

88 _transport_registry["grpc"] = SchemaServiceGrpcTransport 

89 _transport_registry["grpc_asyncio"] = SchemaServiceGrpcAsyncIOTransport 

90 _transport_registry["rest"] = SchemaServiceRestTransport 

91 

92 def get_transport_class( 

93 cls, 

94 label: Optional[str] = None, 

95 ) -> Type[SchemaServiceTransport]: 

96 """Returns an appropriate transport class. 

97 

98 Args: 

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

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

101 

102 Returns: 

103 The transport class to use. 

104 """ 

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

106 if label: 

107 return cls._transport_registry[label] 

108 

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

110 # in the dictionary). 

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

112 

113 

114class SchemaServiceClient(metaclass=SchemaServiceClientMeta): 

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

116 

117 @staticmethod 

118 def _get_default_mtls_endpoint(api_endpoint): 

119 """Converts api endpoint to mTLS endpoint. 

120 

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

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

123 Args: 

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

125 Returns: 

126 str: converted mTLS api endpoint. 

127 """ 

128 if not api_endpoint: 

129 return api_endpoint 

130 

131 mtls_endpoint_re = re.compile( 

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

133 ) 

134 

135 m = mtls_endpoint_re.match(api_endpoint) 

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

137 if mtls or not googledomain: 

138 return api_endpoint 

139 

140 if sandbox: 

141 return api_endpoint.replace( 

142 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" 

143 ) 

144 

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

146 

147 # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. 

148 DEFAULT_ENDPOINT = "pubsub.googleapis.com" 

149 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore 

150 DEFAULT_ENDPOINT 

151 ) 

152 

153 _DEFAULT_ENDPOINT_TEMPLATE = "pubsub.{UNIVERSE_DOMAIN}" 

154 _DEFAULT_UNIVERSE = "googleapis.com" 

155 

156 @staticmethod 

157 def _use_client_cert_effective(): 

158 """Returns whether client certificate should be used for mTLS if the 

159 google-auth version supports should_use_client_cert automatic mTLS enablement. 

160 

161 Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var. 

162 

163 Returns: 

164 bool: whether client certificate should be used for mTLS 

165 Raises: 

166 ValueError: (If using a version of google-auth without should_use_client_cert and 

167 GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.) 

168 """ 

169 # check if google-auth version supports should_use_client_cert for automatic mTLS enablement 

170 if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER 

171 return mtls.should_use_client_cert() 

172 else: # pragma: NO COVER 

173 # if unsupported, fallback to reading from env var 

174 use_client_cert_str = os.getenv( 

175 "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" 

176 ).lower() 

177 if use_client_cert_str not in ("true", "false"): 

178 raise ValueError( 

179 "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" 

180 " either `true` or `false`" 

181 ) 

182 return use_client_cert_str == "true" 

183 

184 @classmethod 

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

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

187 info. 

188 

189 Args: 

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

191 args: Additional arguments to pass to the constructor. 

192 kwargs: Additional arguments to pass to the constructor. 

193 

194 Returns: 

195 SchemaServiceClient: The constructed client. 

196 """ 

197 credentials = service_account.Credentials.from_service_account_info(info) 

198 kwargs["credentials"] = credentials 

199 return cls(*args, **kwargs) 

200 

201 @classmethod 

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

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

204 file. 

205 

206 Args: 

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

208 file. 

209 args: Additional arguments to pass to the constructor. 

210 kwargs: Additional arguments to pass to the constructor. 

211 

212 Returns: 

213 SchemaServiceClient: The constructed client. 

214 """ 

215 credentials = service_account.Credentials.from_service_account_file(filename) 

216 kwargs["credentials"] = credentials 

217 return cls(*args, **kwargs) 

218 

219 from_service_account_json = from_service_account_file 

220 

221 @property 

222 def transport(self) -> SchemaServiceTransport: 

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

224 

225 Returns: 

226 SchemaServiceTransport: The transport used by the client 

227 instance. 

228 """ 

229 return self._transport 

230 

231 @staticmethod 

232 def schema_path( 

233 project: str, 

234 schema: str, 

235 ) -> str: 

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

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

238 project=project, 

239 schema=schema, 

240 ) 

241 

242 @staticmethod 

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

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

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

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

247 

248 @staticmethod 

249 def common_billing_account_path( 

250 billing_account: str, 

251 ) -> str: 

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

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

254 billing_account=billing_account, 

255 ) 

256 

257 @staticmethod 

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

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

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

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

262 

263 @staticmethod 

264 def common_folder_path( 

265 folder: str, 

266 ) -> str: 

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

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

269 folder=folder, 

270 ) 

271 

272 @staticmethod 

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

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

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

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

277 

278 @staticmethod 

279 def common_organization_path( 

280 organization: str, 

281 ) -> str: 

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

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

284 organization=organization, 

285 ) 

286 

287 @staticmethod 

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

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

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

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

292 

293 @staticmethod 

294 def common_project_path( 

295 project: str, 

296 ) -> str: 

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

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

299 project=project, 

300 ) 

301 

302 @staticmethod 

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

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

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

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

307 

308 @staticmethod 

309 def common_location_path( 

310 project: str, 

311 location: str, 

312 ) -> str: 

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

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

315 project=project, 

316 location=location, 

317 ) 

318 

319 @staticmethod 

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

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

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

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

324 

325 @classmethod 

326 def get_mtls_endpoint_and_cert_source( 

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

328 ): 

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

330 

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

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

333 client cert source is None. 

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

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

336 source is None. 

337 

338 The API endpoint is determined in the following order: 

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

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

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

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

343 use the default API endpoint. 

344 

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

346 

347 Args: 

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

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

350 in this method. 

351 

352 Returns: 

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

354 client cert source to use. 

355 

356 Raises: 

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

358 """ 

359 

360 warnings.warn( 

361 "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.", 

362 DeprecationWarning, 

363 ) 

364 if client_options is None: 

365 client_options = client_options_lib.ClientOptions() 

366 use_client_cert = SchemaServiceClient._use_client_cert_effective() 

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

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

369 raise MutualTLSChannelError( 

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

371 ) 

372 

373 # Figure out the client cert source to use. 

374 client_cert_source = None 

375 if use_client_cert: 

376 if client_options.client_cert_source: 

377 client_cert_source = client_options.client_cert_source 

378 elif mtls.has_default_client_cert_source(): 

379 client_cert_source = mtls.default_client_cert_source() 

380 

381 # Figure out which api endpoint to use. 

382 if client_options.api_endpoint is not None: 

383 api_endpoint = client_options.api_endpoint 

384 elif use_mtls_endpoint == "always" or ( 

385 use_mtls_endpoint == "auto" and client_cert_source 

386 ): 

387 api_endpoint = cls.DEFAULT_MTLS_ENDPOINT 

388 else: 

389 api_endpoint = cls.DEFAULT_ENDPOINT 

390 

391 return api_endpoint, client_cert_source 

392 

393 @staticmethod 

394 def _read_environment_variables(): 

395 """Returns the environment variables used by the client. 

396 

397 Returns: 

398 Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, 

399 GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. 

400 

401 Raises: 

402 ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not 

403 any of ["true", "false"]. 

404 google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT 

405 is not any of ["auto", "never", "always"]. 

406 """ 

407 use_client_cert = SchemaServiceClient._use_client_cert_effective() 

408 use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() 

409 universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") 

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

411 raise MutualTLSChannelError( 

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

413 ) 

414 return use_client_cert, use_mtls_endpoint, universe_domain_env 

415 

416 @staticmethod 

417 def _get_client_cert_source(provided_cert_source, use_cert_flag): 

418 """Return the client cert source to be used by the client. 

419 

420 Args: 

421 provided_cert_source (bytes): The client certificate source provided. 

422 use_cert_flag (bool): A flag indicating whether to use the client certificate. 

423 

424 Returns: 

425 bytes or None: The client cert source to be used by the client. 

426 """ 

427 client_cert_source = None 

428 if use_cert_flag: 

429 if provided_cert_source: 

430 client_cert_source = provided_cert_source 

431 elif mtls.has_default_client_cert_source(): 

432 client_cert_source = mtls.default_client_cert_source() 

433 return client_cert_source 

434 

435 @staticmethod 

436 def _get_api_endpoint( 

437 api_override, client_cert_source, universe_domain, use_mtls_endpoint 

438 ): 

439 """Return the API endpoint used by the client. 

440 

441 Args: 

442 api_override (str): The API endpoint override. If specified, this is always 

443 the return value of this function and the other arguments are not used. 

444 client_cert_source (bytes): The client certificate source used by the client. 

445 universe_domain (str): The universe domain used by the client. 

446 use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters. 

447 Possible values are "always", "auto", or "never". 

448 

449 Returns: 

450 str: The API endpoint to be used by the client. 

451 """ 

452 if api_override is not None: 

453 api_endpoint = api_override 

454 elif use_mtls_endpoint == "always" or ( 

455 use_mtls_endpoint == "auto" and client_cert_source 

456 ): 

457 _default_universe = SchemaServiceClient._DEFAULT_UNIVERSE 

458 if universe_domain != _default_universe: 

459 raise MutualTLSChannelError( 

460 f"mTLS is not supported in any universe other than {_default_universe}." 

461 ) 

462 api_endpoint = SchemaServiceClient.DEFAULT_MTLS_ENDPOINT 

463 else: 

464 api_endpoint = SchemaServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format( 

465 UNIVERSE_DOMAIN=universe_domain 

466 ) 

467 return api_endpoint 

468 

469 @staticmethod 

470 def _get_universe_domain( 

471 client_universe_domain: Optional[str], universe_domain_env: Optional[str] 

472 ) -> str: 

473 """Return the universe domain used by the client. 

474 

475 Args: 

476 client_universe_domain (Optional[str]): The universe domain configured via the client options. 

477 universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable. 

478 

479 Returns: 

480 str: The universe domain to be used by the client. 

481 

482 Raises: 

483 ValueError: If the universe domain is an empty string. 

484 """ 

485 universe_domain = SchemaServiceClient._DEFAULT_UNIVERSE 

486 if client_universe_domain is not None: 

487 universe_domain = client_universe_domain 

488 elif universe_domain_env is not None: 

489 universe_domain = universe_domain_env 

490 if len(universe_domain.strip()) == 0: 

491 raise ValueError("Universe Domain cannot be an empty string.") 

492 return universe_domain 

493 

494 def _validate_universe_domain(self): 

495 """Validates client's and credentials' universe domains are consistent. 

496 

497 Returns: 

498 bool: True iff the configured universe domain is valid. 

499 

500 Raises: 

501 ValueError: If the configured universe domain is not valid. 

502 """ 

503 

504 # NOTE (b/349488459): universe validation is disabled until further notice. 

505 return True 

506 

507 def _add_cred_info_for_auth_errors( 

508 self, error: core_exceptions.GoogleAPICallError 

509 ) -> None: 

510 """Adds credential info string to error details for 401/403/404 errors. 

511 

512 Args: 

513 error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info. 

514 """ 

515 if error.code not in [ 

516 HTTPStatus.UNAUTHORIZED, 

517 HTTPStatus.FORBIDDEN, 

518 HTTPStatus.NOT_FOUND, 

519 ]: 

520 return 

521 

522 cred = self._transport._credentials 

523 

524 # get_cred_info is only available in google-auth>=2.35.0 

525 if not hasattr(cred, "get_cred_info"): 

526 return 

527 

528 # ignore the type check since pypy test fails when get_cred_info 

529 # is not available 

530 cred_info = cred.get_cred_info() # type: ignore 

531 if cred_info and hasattr(error._details, "append"): 

532 error._details.append(json.dumps(cred_info)) 

533 

534 @property 

535 def api_endpoint(self): 

536 """Return the API endpoint used by the client instance. 

537 

538 Returns: 

539 str: The API endpoint used by the client instance. 

540 """ 

541 return self._api_endpoint 

542 

543 @property 

544 def universe_domain(self) -> str: 

545 """Return the universe domain used by the client instance. 

546 

547 Returns: 

548 str: The universe domain used by the client instance. 

549 """ 

550 return self._universe_domain 

551 

552 def __init__( 

553 self, 

554 *, 

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

556 transport: Optional[ 

557 Union[str, SchemaServiceTransport, Callable[..., SchemaServiceTransport]] 

558 ] = None, 

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

560 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

561 ) -> None: 

562 """Instantiates the schema service client. 

563 

564 Args: 

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

566 authorization credentials to attach to requests. These 

567 credentials identify the application to the service; if none 

568 are specified, the client will attempt to ascertain the 

569 credentials from the environment. 

570 transport (Optional[Union[str,SchemaServiceTransport,Callable[..., SchemaServiceTransport]]]): 

571 The transport to use, or a Callable that constructs and returns a new transport. 

572 If a Callable is given, it will be called with the same set of initialization 

573 arguments as used in the SchemaServiceTransport constructor. 

574 If set to None, a transport is chosen automatically. 

575 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): 

576 Custom options for the client. 

577 

578 1. The ``api_endpoint`` property can be used to override the 

579 default endpoint provided by the client when ``transport`` is 

580 not explicitly provided. Only if this property is not set and 

581 ``transport`` was not explicitly provided, the endpoint is 

582 determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment 

583 variable, which have one of the following values: 

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

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

586 default mTLS endpoint if client certificate is present; this is 

587 the default value). 

588 

589 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

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

591 to provide a client certificate for mTLS transport. If 

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

593 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

594 set, no client certificate will be used. 

595 

596 3. The ``universe_domain`` property can be used to override the 

597 default "googleapis.com" universe. Note that the ``api_endpoint`` 

598 property still takes precedence; and ``universe_domain`` is 

599 currently not supported for mTLS. 

600 

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

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

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

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

605 your own client library. 

606 

607 Raises: 

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

609 creation failed for any reason. 

610 """ 

611 self._client_options = client_options 

612 if isinstance(self._client_options, dict): 

613 self._client_options = client_options_lib.from_dict(self._client_options) 

614 if self._client_options is None: 

615 self._client_options = client_options_lib.ClientOptions() 

616 self._client_options = cast( 

617 client_options_lib.ClientOptions, self._client_options 

618 ) 

619 

620 universe_domain_opt = getattr(self._client_options, "universe_domain", None) 

621 

622 ( 

623 self._use_client_cert, 

624 self._use_mtls_endpoint, 

625 self._universe_domain_env, 

626 ) = SchemaServiceClient._read_environment_variables() 

627 self._client_cert_source = SchemaServiceClient._get_client_cert_source( 

628 self._client_options.client_cert_source, self._use_client_cert 

629 ) 

630 self._universe_domain = SchemaServiceClient._get_universe_domain( 

631 universe_domain_opt, self._universe_domain_env 

632 ) 

633 self._api_endpoint = None # updated below, depending on `transport` 

634 

635 # Initialize the universe domain validation. 

636 self._is_universe_domain_valid = False 

637 

638 if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER 

639 # Setup logging. 

640 client_logging.initialize_logging() 

641 

642 api_key_value = getattr(self._client_options, "api_key", None) 

643 if api_key_value and credentials: 

644 raise ValueError( 

645 "client_options.api_key and credentials are mutually exclusive" 

646 ) 

647 

648 # Save or instantiate the transport. 

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

650 # instance provides an extensibility point for unusual situations. 

651 transport_provided = isinstance(transport, SchemaServiceTransport) 

652 if transport_provided: 

653 # transport is a SchemaServiceTransport instance. 

654 if credentials or self._client_options.credentials_file or api_key_value: 

655 raise ValueError( 

656 "When providing a transport instance, " 

657 "provide its credentials directly." 

658 ) 

659 if self._client_options.scopes: 

660 raise ValueError( 

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

662 "directly." 

663 ) 

664 self._transport = cast(SchemaServiceTransport, transport) 

665 self._api_endpoint = self._transport.host 

666 

667 self._api_endpoint = ( 

668 self._api_endpoint 

669 or SchemaServiceClient._get_api_endpoint( 

670 self._client_options.api_endpoint, 

671 self._client_cert_source, 

672 self._universe_domain, 

673 self._use_mtls_endpoint, 

674 ) 

675 ) 

676 

677 if not transport_provided: 

678 import google.auth._default # type: ignore 

679 

680 if api_key_value and hasattr( 

681 google.auth._default, "get_api_key_credentials" 

682 ): 

683 credentials = google.auth._default.get_api_key_credentials( 

684 api_key_value 

685 ) 

686 

687 transport_init: Union[ 

688 Type[SchemaServiceTransport], Callable[..., SchemaServiceTransport] 

689 ] = ( 

690 SchemaServiceClient.get_transport_class(transport) 

691 if isinstance(transport, str) or transport is None 

692 else cast(Callable[..., SchemaServiceTransport], transport) 

693 ) 

694 # initialize with the provided callable or the passed in class 

695 

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

697 if emulator_host: 

698 if issubclass(transport_init, type(self)._transport_registry["grpc"]): # type: ignore 

699 channel = grpc.insecure_channel(target=emulator_host) 

700 else: 

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

702 transport_init = functools.partial(transport_init, channel=channel) 

703 

704 self._transport = transport_init( 

705 credentials=credentials, 

706 credentials_file=self._client_options.credentials_file, 

707 host=self._api_endpoint, 

708 scopes=self._client_options.scopes, 

709 client_cert_source_for_mtls=self._client_cert_source, 

710 quota_project_id=self._client_options.quota_project_id, 

711 client_info=client_info, 

712 always_use_jwt_access=True, 

713 api_audience=self._client_options.api_audience, 

714 ) 

715 

716 if "async" not in str(self._transport): 

717 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

718 std_logging.DEBUG 

719 ): # pragma: NO COVER 

720 _LOGGER.debug( 

721 "Created client `google.pubsub_v1.SchemaServiceClient`.", 

722 extra={ 

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

724 "universeDomain": getattr( 

725 self._transport._credentials, "universe_domain", "" 

726 ), 

727 "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", 

728 "credentialsInfo": getattr( 

729 self.transport._credentials, "get_cred_info", lambda: None 

730 )(), 

731 } 

732 if hasattr(self._transport, "_credentials") 

733 else { 

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

735 "credentialsType": None, 

736 }, 

737 ) 

738 

739 def create_schema( 

740 self, 

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

742 *, 

743 parent: Optional[str] = None, 

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

745 schema_id: Optional[str] = None, 

746 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

748 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

749 ) -> gp_schema.Schema: 

750 r"""Creates a schema. 

751 

752 .. code-block:: python 

753 

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

755 # code template only. 

756 # It will require modifications to work: 

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

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

759 # client as shown in: 

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

761 from google import pubsub_v1 

762 

763 def sample_create_schema(): 

764 # Create a client 

765 client = pubsub_v1.SchemaServiceClient() 

766 

767 # Initialize request argument(s) 

768 schema = pubsub_v1.Schema() 

769 schema.name = "name_value" 

770 

771 request = pubsub_v1.CreateSchemaRequest( 

772 parent="parent_value", 

773 schema=schema, 

774 ) 

775 

776 # Make the request 

777 response = client.create_schema(request=request) 

778 

779 # Handle the response 

780 print(response) 

781 

782 Args: 

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

784 The request object. Request for the CreateSchema method. 

785 parent (str): 

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

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

788 

789 This corresponds to the ``parent`` field 

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

791 should not be set. 

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

793 Required. The schema object to create. 

794 

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

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

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

798 

799 This corresponds to the ``schema`` field 

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

801 should not be set. 

802 schema_id (str): 

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

804 final component of the schema's resource name. 

805 

806 See 

807 https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names 

808 for resource name constraints. 

809 

810 This corresponds to the ``schema_id`` field 

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

812 should not be set. 

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

814 should be retried. 

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

816 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

817 sent along with the request as metadata. Normally, each value must be of type `str`, 

818 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

819 be of type `bytes`. 

820 

821 Returns: 

822 google.pubsub_v1.types.Schema: 

823 A schema resource. 

824 """ 

825 # Create or coerce a protobuf request object. 

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

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

828 flattened_params = [parent, schema, schema_id] 

829 has_flattened_params = ( 

830 len([param for param in flattened_params if param is not None]) > 0 

831 ) 

832 if request is not None and has_flattened_params: 

833 raise ValueError( 

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

835 "the individual field arguments should be set." 

836 ) 

837 

838 # - Use the request object if provided (there's no risk of modifying the input as 

839 # there are no flattened fields), or create one. 

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

841 request = gp_schema.CreateSchemaRequest(request) 

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

843 # request, apply these. 

844 if parent is not None: 

845 request.parent = parent 

846 if schema is not None: 

847 request.schema = schema 

848 if schema_id is not None: 

849 request.schema_id = schema_id 

850 

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

852 # and friendly error handling. 

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

854 

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

856 # add these here. 

857 metadata = tuple(metadata) + ( 

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

859 ) 

860 

861 # Validate the universe domain. 

862 self._validate_universe_domain() 

863 

864 # Send the request. 

865 response = rpc( 

866 request, 

867 retry=retry, 

868 timeout=timeout, 

869 metadata=metadata, 

870 ) 

871 

872 # Done; return the response. 

873 return response 

874 

875 def get_schema( 

876 self, 

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

878 *, 

879 name: Optional[str] = None, 

880 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

882 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

883 ) -> schema.Schema: 

884 r"""Gets a schema. 

885 

886 .. code-block:: python 

887 

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

889 # code template only. 

890 # It will require modifications to work: 

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

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

893 # client as shown in: 

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

895 from google import pubsub_v1 

896 

897 def sample_get_schema(): 

898 # Create a client 

899 client = pubsub_v1.SchemaServiceClient() 

900 

901 # Initialize request argument(s) 

902 request = pubsub_v1.GetSchemaRequest( 

903 name="name_value", 

904 ) 

905 

906 # Make the request 

907 response = client.get_schema(request=request) 

908 

909 # Handle the response 

910 print(response) 

911 

912 Args: 

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

914 The request object. Request for the GetSchema method. 

915 name (str): 

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

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

918 

919 This corresponds to the ``name`` field 

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

921 should not be set. 

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

923 should be retried. 

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

925 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

926 sent along with the request as metadata. Normally, each value must be of type `str`, 

927 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

928 be of type `bytes`. 

929 

930 Returns: 

931 google.pubsub_v1.types.Schema: 

932 A schema resource. 

933 """ 

934 # Create or coerce a protobuf request object. 

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

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

937 flattened_params = [name] 

938 has_flattened_params = ( 

939 len([param for param in flattened_params if param is not None]) > 0 

940 ) 

941 if request is not None and has_flattened_params: 

942 raise ValueError( 

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

944 "the individual field arguments should be set." 

945 ) 

946 

947 # - Use the request object if provided (there's no risk of modifying the input as 

948 # there are no flattened fields), or create one. 

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

950 request = schema.GetSchemaRequest(request) 

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

952 # request, apply these. 

953 if name is not None: 

954 request.name = name 

955 

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

957 # and friendly error handling. 

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

959 

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

961 # add these here. 

962 metadata = tuple(metadata) + ( 

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

964 ) 

965 

966 # Validate the universe domain. 

967 self._validate_universe_domain() 

968 

969 # Send the request. 

970 response = rpc( 

971 request, 

972 retry=retry, 

973 timeout=timeout, 

974 metadata=metadata, 

975 ) 

976 

977 # Done; return the response. 

978 return response 

979 

980 def list_schemas( 

981 self, 

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

983 *, 

984 parent: Optional[str] = None, 

985 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

987 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

988 ) -> pagers.ListSchemasPager: 

989 r"""Lists schemas in a project. 

990 

991 .. code-block:: python 

992 

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

994 # code template only. 

995 # It will require modifications to work: 

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

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

998 # client as shown in: 

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

1000 from google import pubsub_v1 

1001 

1002 def sample_list_schemas(): 

1003 # Create a client 

1004 client = pubsub_v1.SchemaServiceClient() 

1005 

1006 # Initialize request argument(s) 

1007 request = pubsub_v1.ListSchemasRequest( 

1008 parent="parent_value", 

1009 ) 

1010 

1011 # Make the request 

1012 page_result = client.list_schemas(request=request) 

1013 

1014 # Handle the response 

1015 for response in page_result: 

1016 print(response) 

1017 

1018 Args: 

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

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

1021 parent (str): 

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

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

1024 

1025 This corresponds to the ``parent`` field 

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

1027 should not be set. 

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

1029 should be retried. 

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

1031 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1032 sent along with the request as metadata. Normally, each value must be of type `str`, 

1033 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1034 be of type `bytes`. 

1035 

1036 Returns: 

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

1038 Response for the ListSchemas method. 

1039 

1040 Iterating over this object will yield results and 

1041 resolve additional pages automatically. 

1042 

1043 """ 

1044 # Create or coerce a protobuf request object. 

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

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

1047 flattened_params = [parent] 

1048 has_flattened_params = ( 

1049 len([param for param in flattened_params if param is not None]) > 0 

1050 ) 

1051 if request is not None and has_flattened_params: 

1052 raise ValueError( 

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

1054 "the individual field arguments should be set." 

1055 ) 

1056 

1057 # - Use the request object if provided (there's no risk of modifying the input as 

1058 # there are no flattened fields), or create one. 

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

1060 request = schema.ListSchemasRequest(request) 

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

1062 # request, apply these. 

1063 if parent is not None: 

1064 request.parent = parent 

1065 

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

1067 # and friendly error handling. 

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

1069 

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

1071 # add these here. 

1072 metadata = tuple(metadata) + ( 

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

1074 ) 

1075 

1076 # Validate the universe domain. 

1077 self._validate_universe_domain() 

1078 

1079 # Send the request. 

1080 response = rpc( 

1081 request, 

1082 retry=retry, 

1083 timeout=timeout, 

1084 metadata=metadata, 

1085 ) 

1086 

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

1088 # an `__iter__` convenience method. 

1089 response = pagers.ListSchemasPager( 

1090 method=rpc, 

1091 request=request, 

1092 response=response, 

1093 retry=retry, 

1094 timeout=timeout, 

1095 metadata=metadata, 

1096 ) 

1097 

1098 # Done; return the response. 

1099 return response 

1100 

1101 def list_schema_revisions( 

1102 self, 

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

1104 *, 

1105 name: Optional[str] = None, 

1106 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1108 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1109 ) -> pagers.ListSchemaRevisionsPager: 

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

1111 

1112 .. code-block:: python 

1113 

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

1115 # code template only. 

1116 # It will require modifications to work: 

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

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

1119 # client as shown in: 

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

1121 from google import pubsub_v1 

1122 

1123 def sample_list_schema_revisions(): 

1124 # Create a client 

1125 client = pubsub_v1.SchemaServiceClient() 

1126 

1127 # Initialize request argument(s) 

1128 request = pubsub_v1.ListSchemaRevisionsRequest( 

1129 name="name_value", 

1130 ) 

1131 

1132 # Make the request 

1133 page_result = client.list_schema_revisions(request=request) 

1134 

1135 # Handle the response 

1136 for response in page_result: 

1137 print(response) 

1138 

1139 Args: 

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

1141 The request object. Request for the ``ListSchemaRevisions`` method. 

1142 name (str): 

1143 Required. The name of the schema to 

1144 list revisions for. 

1145 

1146 This corresponds to the ``name`` field 

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

1148 should not be set. 

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

1150 should be retried. 

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

1152 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1153 sent along with the request as metadata. Normally, each value must be of type `str`, 

1154 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1155 be of type `bytes`. 

1156 

1157 Returns: 

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

1159 Response for the ListSchemaRevisions method. 

1160 

1161 Iterating over this object will yield results and 

1162 resolve additional pages automatically. 

1163 

1164 """ 

1165 # Create or coerce a protobuf request object. 

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

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

1168 flattened_params = [name] 

1169 has_flattened_params = ( 

1170 len([param for param in flattened_params if param is not None]) > 0 

1171 ) 

1172 if request is not None and has_flattened_params: 

1173 raise ValueError( 

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

1175 "the individual field arguments should be set." 

1176 ) 

1177 

1178 # - Use the request object if provided (there's no risk of modifying the input as 

1179 # there are no flattened fields), or create one. 

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

1181 request = schema.ListSchemaRevisionsRequest(request) 

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

1183 # request, apply these. 

1184 if name is not None: 

1185 request.name = name 

1186 

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

1188 # and friendly error handling. 

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

1190 

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

1192 # add these here. 

1193 metadata = tuple(metadata) + ( 

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

1195 ) 

1196 

1197 # Validate the universe domain. 

1198 self._validate_universe_domain() 

1199 

1200 # Send the request. 

1201 response = rpc( 

1202 request, 

1203 retry=retry, 

1204 timeout=timeout, 

1205 metadata=metadata, 

1206 ) 

1207 

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

1209 # an `__iter__` convenience method. 

1210 response = pagers.ListSchemaRevisionsPager( 

1211 method=rpc, 

1212 request=request, 

1213 response=response, 

1214 retry=retry, 

1215 timeout=timeout, 

1216 metadata=metadata, 

1217 ) 

1218 

1219 # Done; return the response. 

1220 return response 

1221 

1222 def commit_schema( 

1223 self, 

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

1225 *, 

1226 name: Optional[str] = None, 

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

1228 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1230 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1231 ) -> gp_schema.Schema: 

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

1233 

1234 .. code-block:: python 

1235 

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

1237 # code template only. 

1238 # It will require modifications to work: 

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

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

1241 # client as shown in: 

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

1243 from google import pubsub_v1 

1244 

1245 def sample_commit_schema(): 

1246 # Create a client 

1247 client = pubsub_v1.SchemaServiceClient() 

1248 

1249 # Initialize request argument(s) 

1250 schema = pubsub_v1.Schema() 

1251 schema.name = "name_value" 

1252 

1253 request = pubsub_v1.CommitSchemaRequest( 

1254 name="name_value", 

1255 schema=schema, 

1256 ) 

1257 

1258 # Make the request 

1259 response = client.commit_schema(request=request) 

1260 

1261 # Handle the response 

1262 print(response) 

1263 

1264 Args: 

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

1266 The request object. Request for CommitSchema method. 

1267 name (str): 

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

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

1270 

1271 This corresponds to the ``name`` field 

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

1273 should not be set. 

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

1275 Required. The schema revision to 

1276 commit. 

1277 

1278 This corresponds to the ``schema`` field 

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

1280 should not be set. 

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

1282 should be retried. 

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

1284 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1285 sent along with the request as metadata. Normally, each value must be of type `str`, 

1286 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1287 be of type `bytes`. 

1288 

1289 Returns: 

1290 google.pubsub_v1.types.Schema: 

1291 A schema resource. 

1292 """ 

1293 # Create or coerce a protobuf request object. 

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

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

1296 flattened_params = [name, schema] 

1297 has_flattened_params = ( 

1298 len([param for param in flattened_params if param is not None]) > 0 

1299 ) 

1300 if request is not None and has_flattened_params: 

1301 raise ValueError( 

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

1303 "the individual field arguments should be set." 

1304 ) 

1305 

1306 # - Use the request object if provided (there's no risk of modifying the input as 

1307 # there are no flattened fields), or create one. 

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

1309 request = gp_schema.CommitSchemaRequest(request) 

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

1311 # request, apply these. 

1312 if name is not None: 

1313 request.name = name 

1314 if schema is not None: 

1315 request.schema = schema 

1316 

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

1318 # and friendly error handling. 

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

1320 

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

1322 # add these here. 

1323 metadata = tuple(metadata) + ( 

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

1325 ) 

1326 

1327 # Validate the universe domain. 

1328 self._validate_universe_domain() 

1329 

1330 # Send the request. 

1331 response = rpc( 

1332 request, 

1333 retry=retry, 

1334 timeout=timeout, 

1335 metadata=metadata, 

1336 ) 

1337 

1338 # Done; return the response. 

1339 return response 

1340 

1341 def rollback_schema( 

1342 self, 

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

1344 *, 

1345 name: Optional[str] = None, 

1346 revision_id: Optional[str] = None, 

1347 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1349 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1350 ) -> schema.Schema: 

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

1352 revision_id. 

1353 

1354 .. code-block:: python 

1355 

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

1357 # code template only. 

1358 # It will require modifications to work: 

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

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

1361 # client as shown in: 

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

1363 from google import pubsub_v1 

1364 

1365 def sample_rollback_schema(): 

1366 # Create a client 

1367 client = pubsub_v1.SchemaServiceClient() 

1368 

1369 # Initialize request argument(s) 

1370 request = pubsub_v1.RollbackSchemaRequest( 

1371 name="name_value", 

1372 revision_id="revision_id_value", 

1373 ) 

1374 

1375 # Make the request 

1376 response = client.rollback_schema(request=request) 

1377 

1378 # Handle the response 

1379 print(response) 

1380 

1381 Args: 

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

1383 The request object. Request for the ``RollbackSchema`` method. 

1384 name (str): 

1385 Required. The schema being rolled 

1386 back with revision id. 

1387 

1388 This corresponds to the ``name`` field 

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

1390 should not be set. 

1391 revision_id (str): 

1392 Required. The revision ID to roll 

1393 back to. It must be a revision of the 

1394 same schema. 

1395 

1396 Example: c7cfa2a8 

1397 

1398 This corresponds to the ``revision_id`` field 

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

1400 should not be set. 

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

1402 should be retried. 

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

1404 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1405 sent along with the request as metadata. Normally, each value must be of type `str`, 

1406 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1407 be of type `bytes`. 

1408 

1409 Returns: 

1410 google.pubsub_v1.types.Schema: 

1411 A schema resource. 

1412 """ 

1413 # Create or coerce a protobuf request object. 

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

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

1416 flattened_params = [name, revision_id] 

1417 has_flattened_params = ( 

1418 len([param for param in flattened_params if param is not None]) > 0 

1419 ) 

1420 if request is not None and has_flattened_params: 

1421 raise ValueError( 

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

1423 "the individual field arguments should be set." 

1424 ) 

1425 

1426 # - Use the request object if provided (there's no risk of modifying the input as 

1427 # there are no flattened fields), or create one. 

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

1429 request = schema.RollbackSchemaRequest(request) 

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

1431 # request, apply these. 

1432 if name is not None: 

1433 request.name = name 

1434 if revision_id is not None: 

1435 request.revision_id = revision_id 

1436 

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

1438 # and friendly error handling. 

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

1440 

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

1442 # add these here. 

1443 metadata = tuple(metadata) + ( 

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

1445 ) 

1446 

1447 # Validate the universe domain. 

1448 self._validate_universe_domain() 

1449 

1450 # Send the request. 

1451 response = rpc( 

1452 request, 

1453 retry=retry, 

1454 timeout=timeout, 

1455 metadata=metadata, 

1456 ) 

1457 

1458 # Done; return the response. 

1459 return response 

1460 

1461 def delete_schema_revision( 

1462 self, 

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

1464 *, 

1465 name: Optional[str] = None, 

1466 revision_id: Optional[str] = None, 

1467 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1469 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1470 ) -> schema.Schema: 

1471 r"""Deletes a specific schema revision. 

1472 

1473 .. code-block:: python 

1474 

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

1476 # code template only. 

1477 # It will require modifications to work: 

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

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

1480 # client as shown in: 

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

1482 from google import pubsub_v1 

1483 

1484 def sample_delete_schema_revision(): 

1485 # Create a client 

1486 client = pubsub_v1.SchemaServiceClient() 

1487 

1488 # Initialize request argument(s) 

1489 request = pubsub_v1.DeleteSchemaRevisionRequest( 

1490 name="name_value", 

1491 ) 

1492 

1493 # Make the request 

1494 response = client.delete_schema_revision(request=request) 

1495 

1496 # Handle the response 

1497 print(response) 

1498 

1499 Args: 

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

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

1502 name (str): 

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

1504 with a revision ID explicitly included. 

1505 

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

1507 

1508 This corresponds to the ``name`` field 

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

1510 should not be set. 

1511 revision_id (str): 

1512 Optional. This field is deprecated and should not be 

1513 used for specifying the revision ID. The revision ID 

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

1515 

1516 This corresponds to the ``revision_id`` field 

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

1518 should not be set. 

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

1520 should be retried. 

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

1522 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1523 sent along with the request as metadata. Normally, each value must be of type `str`, 

1524 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1525 be of type `bytes`. 

1526 

1527 Returns: 

1528 google.pubsub_v1.types.Schema: 

1529 A schema resource. 

1530 """ 

1531 # Create or coerce a protobuf request object. 

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

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

1534 flattened_params = [name, revision_id] 

1535 has_flattened_params = ( 

1536 len([param for param in flattened_params if param is not None]) > 0 

1537 ) 

1538 if request is not None and has_flattened_params: 

1539 raise ValueError( 

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

1541 "the individual field arguments should be set." 

1542 ) 

1543 

1544 # - Use the request object if provided (there's no risk of modifying the input as 

1545 # there are no flattened fields), or create one. 

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

1547 request = schema.DeleteSchemaRevisionRequest(request) 

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

1549 # request, apply these. 

1550 if name is not None: 

1551 request.name = name 

1552 if revision_id is not None: 

1553 request.revision_id = revision_id 

1554 

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

1556 # and friendly error handling. 

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

1558 

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

1560 # add these here. 

1561 metadata = tuple(metadata) + ( 

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

1563 ) 

1564 

1565 # Validate the universe domain. 

1566 self._validate_universe_domain() 

1567 

1568 # Send the request. 

1569 response = rpc( 

1570 request, 

1571 retry=retry, 

1572 timeout=timeout, 

1573 metadata=metadata, 

1574 ) 

1575 

1576 # Done; return the response. 

1577 return response 

1578 

1579 def delete_schema( 

1580 self, 

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

1582 *, 

1583 name: Optional[str] = None, 

1584 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1586 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1587 ) -> None: 

1588 r"""Deletes a schema. 

1589 

1590 .. code-block:: python 

1591 

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

1593 # code template only. 

1594 # It will require modifications to work: 

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

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

1597 # client as shown in: 

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

1599 from google import pubsub_v1 

1600 

1601 def sample_delete_schema(): 

1602 # Create a client 

1603 client = pubsub_v1.SchemaServiceClient() 

1604 

1605 # Initialize request argument(s) 

1606 request = pubsub_v1.DeleteSchemaRequest( 

1607 name="name_value", 

1608 ) 

1609 

1610 # Make the request 

1611 client.delete_schema(request=request) 

1612 

1613 Args: 

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

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

1616 name (str): 

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

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

1619 

1620 This corresponds to the ``name`` field 

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

1622 should not be set. 

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

1624 should be retried. 

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

1626 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1627 sent along with the request as metadata. Normally, each value must be of type `str`, 

1628 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1629 be of type `bytes`. 

1630 """ 

1631 # Create or coerce a protobuf request object. 

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

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

1634 flattened_params = [name] 

1635 has_flattened_params = ( 

1636 len([param for param in flattened_params if param is not None]) > 0 

1637 ) 

1638 if request is not None and has_flattened_params: 

1639 raise ValueError( 

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

1641 "the individual field arguments should be set." 

1642 ) 

1643 

1644 # - Use the request object if provided (there's no risk of modifying the input as 

1645 # there are no flattened fields), or create one. 

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

1647 request = schema.DeleteSchemaRequest(request) 

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

1649 # request, apply these. 

1650 if name is not None: 

1651 request.name = name 

1652 

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

1654 # and friendly error handling. 

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

1656 

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

1658 # add these here. 

1659 metadata = tuple(metadata) + ( 

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

1661 ) 

1662 

1663 # Validate the universe domain. 

1664 self._validate_universe_domain() 

1665 

1666 # Send the request. 

1667 rpc( 

1668 request, 

1669 retry=retry, 

1670 timeout=timeout, 

1671 metadata=metadata, 

1672 ) 

1673 

1674 def validate_schema( 

1675 self, 

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

1677 *, 

1678 parent: Optional[str] = None, 

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

1680 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1682 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1683 ) -> gp_schema.ValidateSchemaResponse: 

1684 r"""Validates a schema. 

1685 

1686 .. code-block:: python 

1687 

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

1689 # code template only. 

1690 # It will require modifications to work: 

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

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

1693 # client as shown in: 

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

1695 from google import pubsub_v1 

1696 

1697 def sample_validate_schema(): 

1698 # Create a client 

1699 client = pubsub_v1.SchemaServiceClient() 

1700 

1701 # Initialize request argument(s) 

1702 schema = pubsub_v1.Schema() 

1703 schema.name = "name_value" 

1704 

1705 request = pubsub_v1.ValidateSchemaRequest( 

1706 parent="parent_value", 

1707 schema=schema, 

1708 ) 

1709 

1710 # Make the request 

1711 response = client.validate_schema(request=request) 

1712 

1713 # Handle the response 

1714 print(response) 

1715 

1716 Args: 

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

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

1719 parent (str): 

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

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

1722 

1723 This corresponds to the ``parent`` field 

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

1725 should not be set. 

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

1727 Required. The schema object to 

1728 validate. 

1729 

1730 This corresponds to the ``schema`` field 

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

1732 should not be set. 

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

1734 should be retried. 

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

1736 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1737 sent along with the request as metadata. Normally, each value must be of type `str`, 

1738 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1739 be of type `bytes`. 

1740 

1741 Returns: 

1742 google.pubsub_v1.types.ValidateSchemaResponse: 

1743 Response for the ValidateSchema method. 

1744 Empty for now. 

1745 

1746 """ 

1747 # Create or coerce a protobuf request object. 

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

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

1750 flattened_params = [parent, schema] 

1751 has_flattened_params = ( 

1752 len([param for param in flattened_params if param is not None]) > 0 

1753 ) 

1754 if request is not None and has_flattened_params: 

1755 raise ValueError( 

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

1757 "the individual field arguments should be set." 

1758 ) 

1759 

1760 # - Use the request object if provided (there's no risk of modifying the input as 

1761 # there are no flattened fields), or create one. 

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

1763 request = gp_schema.ValidateSchemaRequest(request) 

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

1765 # request, apply these. 

1766 if parent is not None: 

1767 request.parent = parent 

1768 if schema is not None: 

1769 request.schema = schema 

1770 

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

1772 # and friendly error handling. 

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

1774 

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

1776 # add these here. 

1777 metadata = tuple(metadata) + ( 

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

1779 ) 

1780 

1781 # Validate the universe domain. 

1782 self._validate_universe_domain() 

1783 

1784 # Send the request. 

1785 response = rpc( 

1786 request, 

1787 retry=retry, 

1788 timeout=timeout, 

1789 metadata=metadata, 

1790 ) 

1791 

1792 # Done; return the response. 

1793 return response 

1794 

1795 def validate_message( 

1796 self, 

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

1798 *, 

1799 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1801 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1802 ) -> schema.ValidateMessageResponse: 

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

1804 

1805 .. code-block:: python 

1806 

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

1808 # code template only. 

1809 # It will require modifications to work: 

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

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

1812 # client as shown in: 

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

1814 from google import pubsub_v1 

1815 

1816 def sample_validate_message(): 

1817 # Create a client 

1818 client = pubsub_v1.SchemaServiceClient() 

1819 

1820 # Initialize request argument(s) 

1821 request = pubsub_v1.ValidateMessageRequest( 

1822 name="name_value", 

1823 parent="parent_value", 

1824 ) 

1825 

1826 # Make the request 

1827 response = client.validate_message(request=request) 

1828 

1829 # Handle the response 

1830 print(response) 

1831 

1832 Args: 

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

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

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

1836 should be retried. 

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

1838 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1839 sent along with the request as metadata. Normally, each value must be of type `str`, 

1840 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1841 be of type `bytes`. 

1842 

1843 Returns: 

1844 google.pubsub_v1.types.ValidateMessageResponse: 

1845 Response for the ValidateMessage method. 

1846 Empty for now. 

1847 

1848 """ 

1849 # Create or coerce a protobuf request object. 

1850 # - Use the request object if provided (there's no risk of modifying the input as 

1851 # there are no flattened fields), or create one. 

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

1853 request = schema.ValidateMessageRequest(request) 

1854 

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

1856 # and friendly error handling. 

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

1858 

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

1860 # add these here. 

1861 metadata = tuple(metadata) + ( 

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

1863 ) 

1864 

1865 # Validate the universe domain. 

1866 self._validate_universe_domain() 

1867 

1868 # Send the request. 

1869 response = rpc( 

1870 request, 

1871 retry=retry, 

1872 timeout=timeout, 

1873 metadata=metadata, 

1874 ) 

1875 

1876 # Done; return the response. 

1877 return response 

1878 

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

1880 return self 

1881 

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

1883 """Releases underlying transport's resources. 

1884 

1885 .. warning:: 

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

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

1888 and may cause errors in other clients! 

1889 """ 

1890 self.transport.close() 

1891 

1892 def set_iam_policy( 

1893 self, 

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

1895 *, 

1896 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

1898 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

1899 ) -> policy_pb2.Policy: 

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

1901 

1902 Replaces any existing policy. 

1903 

1904 Args: 

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

1906 The request object. Request message for `SetIamPolicy` 

1907 method. 

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

1909 should be retried. 

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

1911 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

1912 sent along with the request as metadata. Normally, each value must be of type `str`, 

1913 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

1914 be of type `bytes`. 

1915 Returns: 

1916 ~.policy_pb2.Policy: 

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

1918 It is used to specify access control policies for Cloud 

1919 Platform resources. 

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

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

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

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

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

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

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

1927 expression that further constrains the role binding 

1928 based on attributes about the request and/or target 

1929 resource. 

1930 

1931 **JSON Example** 

1932 

1933 :: 

1934 

1935 { 

1936 "bindings": [ 

1937 { 

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

1939 "members": [ 

1940 "user:mike@example.com", 

1941 "group:admins@example.com", 

1942 "domain:google.com", 

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

1944 ] 

1945 }, 

1946 { 

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

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

1949 "condition": { 

1950 "title": "expirable access", 

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

1952 "expression": "request.time < 

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

1954 } 

1955 } 

1956 ] 

1957 } 

1958 

1959 **YAML Example** 

1960 

1961 :: 

1962 

1963 bindings: 

1964 - members: 

1965 - user:mike@example.com 

1966 - group:admins@example.com 

1967 - domain:google.com 

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

1969 role: roles/resourcemanager.organizationAdmin 

1970 - members: 

1971 - user:eve@example.com 

1972 role: roles/resourcemanager.organizationViewer 

1973 condition: 

1974 title: expirable access 

1975 description: Does not grant access after Sep 2020 

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

1977 

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

1979 developer's 

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

1981 """ 

1982 # Create or coerce a protobuf request object. 

1983 

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

1985 # so it must be constructed via keyword expansion. 

1986 if isinstance(request, dict): 

1987 request = iam_policy_pb2.SetIamPolicyRequest(**request) 

1988 

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

1990 # and friendly error handling. 

1991 rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] 

1992 

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

1994 # add these here. 

1995 metadata = tuple(metadata) + ( 

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

1997 ) 

1998 

1999 # Validate the universe domain. 

2000 self._validate_universe_domain() 

2001 

2002 try: 

2003 # Send the request. 

2004 response = rpc( 

2005 request, 

2006 retry=retry, 

2007 timeout=timeout, 

2008 metadata=metadata, 

2009 ) 

2010 

2011 # Done; return the response. 

2012 return response 

2013 except core_exceptions.GoogleAPICallError as e: 

2014 self._add_cred_info_for_auth_errors(e) 

2015 raise e 

2016 

2017 def get_iam_policy( 

2018 self, 

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

2020 *, 

2021 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

2023 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2024 ) -> policy_pb2.Policy: 

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

2026 

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

2028 policy set. 

2029 

2030 Args: 

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

2032 The request object. Request message for `GetIamPolicy` 

2033 method. 

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

2035 any, should be retried. 

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

2037 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2038 sent along with the request as metadata. Normally, each value must be of type `str`, 

2039 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2040 be of type `bytes`. 

2041 Returns: 

2042 ~.policy_pb2.Policy: 

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

2044 It is used to specify access control policies for Cloud 

2045 Platform resources. 

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

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

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

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

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

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

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

2053 expression that further constrains the role binding 

2054 based on attributes about the request and/or target 

2055 resource. 

2056 

2057 **JSON Example** 

2058 

2059 :: 

2060 

2061 { 

2062 "bindings": [ 

2063 { 

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

2065 "members": [ 

2066 "user:mike@example.com", 

2067 "group:admins@example.com", 

2068 "domain:google.com", 

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

2070 ] 

2071 }, 

2072 { 

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

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

2075 "condition": { 

2076 "title": "expirable access", 

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

2078 "expression": "request.time < 

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

2080 } 

2081 } 

2082 ] 

2083 } 

2084 

2085 **YAML Example** 

2086 

2087 :: 

2088 

2089 bindings: 

2090 - members: 

2091 - user:mike@example.com 

2092 - group:admins@example.com 

2093 - domain:google.com 

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

2095 role: roles/resourcemanager.organizationAdmin 

2096 - members: 

2097 - user:eve@example.com 

2098 role: roles/resourcemanager.organizationViewer 

2099 condition: 

2100 title: expirable access 

2101 description: Does not grant access after Sep 2020 

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

2103 

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

2105 developer's 

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

2107 """ 

2108 # Create or coerce a protobuf request object. 

2109 

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

2111 # so it must be constructed via keyword expansion. 

2112 if isinstance(request, dict): 

2113 request = iam_policy_pb2.GetIamPolicyRequest(**request) 

2114 

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

2116 # and friendly error handling. 

2117 rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] 

2118 

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

2120 # add these here. 

2121 metadata = tuple(metadata) + ( 

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

2123 ) 

2124 

2125 # Validate the universe domain. 

2126 self._validate_universe_domain() 

2127 

2128 try: 

2129 # Send the request. 

2130 response = rpc( 

2131 request, 

2132 retry=retry, 

2133 timeout=timeout, 

2134 metadata=metadata, 

2135 ) 

2136 

2137 # Done; return the response. 

2138 return response 

2139 except core_exceptions.GoogleAPICallError as e: 

2140 self._add_cred_info_for_auth_errors(e) 

2141 raise e 

2142 

2143 def test_iam_permissions( 

2144 self, 

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

2146 *, 

2147 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

2149 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

2150 ) -> iam_policy_pb2.TestIamPermissionsResponse: 

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

2152 policy for a function. 

2153 

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

2155 of permissions, not a NOT_FOUND error. 

2156 

2157 Args: 

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

2159 The request object. Request message for 

2160 `TestIamPermissions` method. 

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

2162 if any, should be retried. 

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

2164 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

2165 sent along with the request as metadata. Normally, each value must be of type `str`, 

2166 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

2167 be of type `bytes`. 

2168 Returns: 

2169 ~.iam_policy_pb2.TestIamPermissionsResponse: 

2170 Response message for ``TestIamPermissions`` method. 

2171 """ 

2172 # Create or coerce a protobuf request object. 

2173 

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

2175 # so it must be constructed via keyword expansion. 

2176 if isinstance(request, dict): 

2177 request = iam_policy_pb2.TestIamPermissionsRequest(**request) 

2178 

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

2180 # and friendly error handling. 

2181 rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] 

2182 

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

2184 # add these here. 

2185 metadata = tuple(metadata) + ( 

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

2187 ) 

2188 

2189 # Validate the universe domain. 

2190 self._validate_universe_domain() 

2191 

2192 try: 

2193 # Send the request. 

2194 response = rpc( 

2195 request, 

2196 retry=retry, 

2197 timeout=timeout, 

2198 metadata=metadata, 

2199 ) 

2200 

2201 # Done; return the response. 

2202 return response 

2203 except core_exceptions.GoogleAPICallError as e: 

2204 self._add_cred_info_for_auth_errors(e) 

2205 raise e 

2206 

2207 

2208DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

2209 client_library_version=package_version.__version__ 

2210) 

2211 

2212if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER 

2213 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ 

2214 

2215__all__ = ("SchemaServiceClient",)