google-cloud-maintenance-api 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. google/cloud/maintenance_api/__init__.py +51 -0
  2. google/cloud/maintenance_api/gapic_version.py +16 -0
  3. google/cloud/maintenance_api/py.typed +2 -0
  4. google/cloud/maintenance_api_v1beta/__init__.py +46 -0
  5. google/cloud/maintenance_api_v1beta/gapic_metadata.json +73 -0
  6. google/cloud/maintenance_api_v1beta/gapic_version.py +16 -0
  7. google/cloud/maintenance_api_v1beta/py.typed +2 -0
  8. google/cloud/maintenance_api_v1beta/services/__init__.py +15 -0
  9. google/cloud/maintenance_api_v1beta/services/maintenance/__init__.py +22 -0
  10. google/cloud/maintenance_api_v1beta/services/maintenance/async_client.py +786 -0
  11. google/cloud/maintenance_api_v1beta/services/maintenance/client.py +1211 -0
  12. google/cloud/maintenance_api_v1beta/services/maintenance/pagers.py +361 -0
  13. google/cloud/maintenance_api_v1beta/services/maintenance/transports/__init__.py +36 -0
  14. google/cloud/maintenance_api_v1beta/services/maintenance/transports/base.py +234 -0
  15. google/cloud/maintenance_api_v1beta/services/maintenance/transports/grpc.py +456 -0
  16. google/cloud/maintenance_api_v1beta/services/maintenance/transports/grpc_asyncio.py +499 -0
  17. google/cloud/maintenance_api_v1beta/services/maintenance/transports/rest.py +1182 -0
  18. google/cloud/maintenance_api_v1beta/services/maintenance/transports/rest_base.py +283 -0
  19. google/cloud/maintenance_api_v1beta/types/__init__.py +38 -0
  20. google/cloud/maintenance_api_v1beta/types/maintenance_service.py +713 -0
  21. google_cloud_maintenance_api-0.1.0.dist-info/METADATA +239 -0
  22. google_cloud_maintenance_api-0.1.0.dist-info/RECORD +25 -0
  23. google_cloud_maintenance_api-0.1.0.dist-info/WHEEL +5 -0
  24. google_cloud_maintenance_api-0.1.0.dist-info/licenses/LICENSE +202 -0
  25. google_cloud_maintenance_api-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,499 @@
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
+ #
16
+ import inspect
17
+ import json
18
+ import logging as std_logging
19
+ import pickle
20
+ from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union
21
+ import warnings
22
+
23
+ from google.api_core import exceptions as core_exceptions
24
+ from google.api_core import gapic_v1, grpc_helpers_async
25
+ from google.api_core import retry_async as retries
26
+ from google.auth import credentials as ga_credentials # type: ignore
27
+ from google.auth.transport.grpc import SslCredentials # type: ignore
28
+ from google.cloud.location import locations_pb2 # type: ignore
29
+ from google.protobuf.json_format import MessageToJson
30
+ import google.protobuf.message
31
+ import grpc # type: ignore
32
+ from grpc.experimental import aio # type: ignore
33
+ import proto # type: ignore
34
+
35
+ from google.cloud.maintenance_api_v1beta.types import maintenance_service
36
+
37
+ from .base import DEFAULT_CLIENT_INFO, MaintenanceTransport
38
+ from .grpc import MaintenanceGrpcTransport
39
+
40
+ try:
41
+ from google.api_core import client_logging # type: ignore
42
+
43
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
44
+ except ImportError: # pragma: NO COVER
45
+ CLIENT_LOGGING_SUPPORTED = False
46
+
47
+ _LOGGER = std_logging.getLogger(__name__)
48
+
49
+
50
+ class _LoggingClientAIOInterceptor(
51
+ grpc.aio.UnaryUnaryClientInterceptor
52
+ ): # pragma: NO COVER
53
+ async def intercept_unary_unary(self, continuation, client_call_details, request):
54
+ logging_enabled = CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
55
+ std_logging.DEBUG
56
+ )
57
+ if logging_enabled: # pragma: NO COVER
58
+ request_metadata = client_call_details.metadata
59
+ if isinstance(request, proto.Message):
60
+ request_payload = type(request).to_json(request)
61
+ elif isinstance(request, google.protobuf.message.Message):
62
+ request_payload = MessageToJson(request)
63
+ else:
64
+ request_payload = f"{type(request).__name__}: {pickle.dumps(request)}"
65
+
66
+ request_metadata = {
67
+ key: value.decode("utf-8") if isinstance(value, bytes) else value
68
+ for key, value in request_metadata
69
+ }
70
+ grpc_request = {
71
+ "payload": request_payload,
72
+ "requestMethod": "grpc",
73
+ "metadata": dict(request_metadata),
74
+ }
75
+ _LOGGER.debug(
76
+ f"Sending request for {client_call_details.method}",
77
+ extra={
78
+ "serviceName": "google.cloud.maintenance.api.v1beta.Maintenance",
79
+ "rpcName": str(client_call_details.method),
80
+ "request": grpc_request,
81
+ "metadata": grpc_request["metadata"],
82
+ },
83
+ )
84
+ response = await continuation(client_call_details, request)
85
+ if logging_enabled: # pragma: NO COVER
86
+ response_metadata = await response.trailing_metadata()
87
+ # Convert gRPC metadata `<class 'grpc.aio._metadata.Metadata'>` to list of tuples
88
+ metadata = (
89
+ dict([(k, str(v)) for k, v in response_metadata])
90
+ if response_metadata
91
+ else None
92
+ )
93
+ result = await response
94
+ if isinstance(result, proto.Message):
95
+ response_payload = type(result).to_json(result)
96
+ elif isinstance(result, google.protobuf.message.Message):
97
+ response_payload = MessageToJson(result)
98
+ else:
99
+ response_payload = f"{type(result).__name__}: {pickle.dumps(result)}"
100
+ grpc_response = {
101
+ "payload": response_payload,
102
+ "metadata": metadata,
103
+ "status": "OK",
104
+ }
105
+ _LOGGER.debug(
106
+ f"Received response to rpc {client_call_details.method}.",
107
+ extra={
108
+ "serviceName": "google.cloud.maintenance.api.v1beta.Maintenance",
109
+ "rpcName": str(client_call_details.method),
110
+ "response": grpc_response,
111
+ "metadata": grpc_response["metadata"],
112
+ },
113
+ )
114
+ return response
115
+
116
+
117
+ class MaintenanceGrpcAsyncIOTransport(MaintenanceTransport):
118
+ """gRPC AsyncIO backend transport for Maintenance.
119
+
120
+ Unified Maintenance service
121
+
122
+ This class defines the same methods as the primary client, so the
123
+ primary client can load the underlying transport implementation
124
+ and call it.
125
+
126
+ It sends protocol buffers over the wire using gRPC (which is built on
127
+ top of HTTP/2); the ``grpcio`` package must be installed.
128
+ """
129
+
130
+ _grpc_channel: aio.Channel
131
+ _stubs: Dict[str, Callable] = {}
132
+
133
+ @classmethod
134
+ def create_channel(
135
+ cls,
136
+ host: str = "maintenance.googleapis.com",
137
+ credentials: Optional[ga_credentials.Credentials] = None,
138
+ credentials_file: Optional[str] = None,
139
+ scopes: Optional[Sequence[str]] = None,
140
+ quota_project_id: Optional[str] = None,
141
+ **kwargs,
142
+ ) -> aio.Channel:
143
+ """Create and return a gRPC AsyncIO channel object.
144
+ Args:
145
+ host (Optional[str]): The host for the channel to use.
146
+ credentials (Optional[~.Credentials]): The
147
+ authorization credentials to attach to requests. These
148
+ credentials identify this application to the service. If
149
+ none are specified, the client will attempt to ascertain
150
+ the credentials from the environment.
151
+ credentials_file (Optional[str]): A file with credentials that can
152
+ be loaded with :func:`google.auth.load_credentials_from_file`.
153
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
154
+ service. These are only used when credentials are not specified and
155
+ are passed to :func:`google.auth.default`.
156
+ quota_project_id (Optional[str]): An optional project to use for billing
157
+ and quota.
158
+ kwargs (Optional[dict]): Keyword arguments, which are passed to the
159
+ channel creation.
160
+ Returns:
161
+ aio.Channel: A gRPC AsyncIO channel object.
162
+ """
163
+
164
+ return grpc_helpers_async.create_channel(
165
+ host,
166
+ credentials=credentials,
167
+ credentials_file=credentials_file,
168
+ quota_project_id=quota_project_id,
169
+ default_scopes=cls.AUTH_SCOPES,
170
+ scopes=scopes,
171
+ default_host=cls.DEFAULT_HOST,
172
+ **kwargs,
173
+ )
174
+
175
+ def __init__(
176
+ self,
177
+ *,
178
+ host: str = "maintenance.googleapis.com",
179
+ credentials: Optional[ga_credentials.Credentials] = None,
180
+ credentials_file: Optional[str] = None,
181
+ scopes: Optional[Sequence[str]] = None,
182
+ channel: Optional[Union[aio.Channel, Callable[..., aio.Channel]]] = None,
183
+ api_mtls_endpoint: Optional[str] = None,
184
+ client_cert_source: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
185
+ ssl_channel_credentials: Optional[grpc.ChannelCredentials] = None,
186
+ client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
187
+ quota_project_id: Optional[str] = None,
188
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
189
+ always_use_jwt_access: Optional[bool] = False,
190
+ api_audience: Optional[str] = None,
191
+ ) -> None:
192
+ """Instantiate the transport.
193
+
194
+ Args:
195
+ host (Optional[str]):
196
+ The hostname to connect to (default: 'maintenance.googleapis.com').
197
+ credentials (Optional[google.auth.credentials.Credentials]): The
198
+ authorization credentials to attach to requests. These
199
+ credentials identify the application to the service; if none
200
+ are specified, the client will attempt to ascertain the
201
+ credentials from the environment.
202
+ This argument is ignored if a ``channel`` instance is provided.
203
+ credentials_file (Optional[str]): A file with credentials that can
204
+ be loaded with :func:`google.auth.load_credentials_from_file`.
205
+ This argument is ignored if a ``channel`` instance is provided.
206
+ scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
207
+ service. These are only used when credentials are not specified and
208
+ are passed to :func:`google.auth.default`.
209
+ channel (Optional[Union[aio.Channel, Callable[..., aio.Channel]]]):
210
+ A ``Channel`` instance through which to make calls, or a Callable
211
+ that constructs and returns one. If set to None, ``self.create_channel``
212
+ is used to create the channel. If a Callable is given, it will be called
213
+ with the same arguments as used in ``self.create_channel``.
214
+ api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
215
+ If provided, it overrides the ``host`` argument and tries to create
216
+ a mutual TLS channel with client SSL credentials from
217
+ ``client_cert_source`` or application default SSL credentials.
218
+ client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
219
+ Deprecated. A callback to provide client SSL certificate bytes and
220
+ private key bytes, both in PEM format. It is ignored if
221
+ ``api_mtls_endpoint`` is None.
222
+ ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
223
+ for the grpc channel. It is ignored if a ``channel`` instance is provided.
224
+ client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
225
+ A callback to provide client certificate bytes and private key bytes,
226
+ both in PEM format. It is used to configure a mutual TLS channel. It is
227
+ ignored if a ``channel`` instance or ``ssl_channel_credentials`` is provided.
228
+ quota_project_id (Optional[str]): An optional project to use for billing
229
+ and quota.
230
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
231
+ The client info used to send a user-agent string along with
232
+ API requests. If ``None``, then default info will be used.
233
+ Generally, you only need to set this if you're developing
234
+ your own client library.
235
+ always_use_jwt_access (Optional[bool]): Whether self signed JWT should
236
+ be used for service account credentials.
237
+
238
+ Raises:
239
+ google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
240
+ creation failed for any reason.
241
+ google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
242
+ and ``credentials_file`` are passed.
243
+ """
244
+ self._grpc_channel = None
245
+ self._ssl_channel_credentials = ssl_channel_credentials
246
+ self._stubs: Dict[str, Callable] = {}
247
+
248
+ if api_mtls_endpoint:
249
+ warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
250
+ if client_cert_source:
251
+ warnings.warn("client_cert_source is deprecated", DeprecationWarning)
252
+
253
+ if isinstance(channel, aio.Channel):
254
+ # Ignore credentials if a channel was passed.
255
+ credentials = None
256
+ self._ignore_credentials = True
257
+ # If a channel was explicitly provided, set it.
258
+ self._grpc_channel = channel
259
+ self._ssl_channel_credentials = None
260
+ else:
261
+ if api_mtls_endpoint:
262
+ host = api_mtls_endpoint
263
+
264
+ # Create SSL credentials with client_cert_source or application
265
+ # default SSL credentials.
266
+ if client_cert_source:
267
+ cert, key = client_cert_source()
268
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
269
+ certificate_chain=cert, private_key=key
270
+ )
271
+ else:
272
+ self._ssl_channel_credentials = SslCredentials().ssl_credentials
273
+
274
+ else:
275
+ if client_cert_source_for_mtls and not ssl_channel_credentials:
276
+ cert, key = client_cert_source_for_mtls()
277
+ self._ssl_channel_credentials = grpc.ssl_channel_credentials(
278
+ certificate_chain=cert, private_key=key
279
+ )
280
+
281
+ # The base transport sets the host, credentials and scopes
282
+ super().__init__(
283
+ host=host,
284
+ credentials=credentials,
285
+ credentials_file=credentials_file,
286
+ scopes=scopes,
287
+ quota_project_id=quota_project_id,
288
+ client_info=client_info,
289
+ always_use_jwt_access=always_use_jwt_access,
290
+ api_audience=api_audience,
291
+ )
292
+
293
+ if not self._grpc_channel:
294
+ # initialize with the provided callable or the default channel
295
+ channel_init = channel or type(self).create_channel
296
+ self._grpc_channel = channel_init(
297
+ self._host,
298
+ # use the credentials which are saved
299
+ credentials=self._credentials,
300
+ # Set ``credentials_file`` to ``None`` here as
301
+ # the credentials that we saved earlier should be used.
302
+ credentials_file=None,
303
+ scopes=self._scopes,
304
+ ssl_credentials=self._ssl_channel_credentials,
305
+ quota_project_id=quota_project_id,
306
+ options=[
307
+ ("grpc.max_send_message_length", -1),
308
+ ("grpc.max_receive_message_length", -1),
309
+ ],
310
+ )
311
+
312
+ self._interceptor = _LoggingClientAIOInterceptor()
313
+ self._grpc_channel._unary_unary_interceptors.append(self._interceptor)
314
+ self._logged_channel = self._grpc_channel
315
+ self._wrap_with_kind = (
316
+ "kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters
317
+ )
318
+ # Wrap messages. This must be done after self._logged_channel exists
319
+ self._prep_wrapped_messages(client_info)
320
+
321
+ @property
322
+ def grpc_channel(self) -> aio.Channel:
323
+ """Create the channel designed to connect to this service.
324
+
325
+ This property caches on the instance; repeated calls return
326
+ the same channel.
327
+ """
328
+ # Return the channel from cache.
329
+ return self._grpc_channel
330
+
331
+ @property
332
+ def summarize_maintenances(
333
+ self,
334
+ ) -> Callable[
335
+ [maintenance_service.SummarizeMaintenancesRequest],
336
+ Awaitable[maintenance_service.SummarizeMaintenancesResponse],
337
+ ]:
338
+ r"""Return a callable for the summarize maintenances method over gRPC.
339
+
340
+ Retrieves the statistics of a specific maintenance.
341
+
342
+ Returns:
343
+ Callable[[~.SummarizeMaintenancesRequest],
344
+ Awaitable[~.SummarizeMaintenancesResponse]]:
345
+ A function that, when called, will call the underlying RPC
346
+ on the server.
347
+ """
348
+ # Generate a "stub function" on-the-fly which will actually make
349
+ # the request.
350
+ # gRPC handles serialization and deserialization, so we just need
351
+ # to pass in the functions for each.
352
+ if "summarize_maintenances" not in self._stubs:
353
+ self._stubs["summarize_maintenances"] = self._logged_channel.unary_unary(
354
+ "/google.cloud.maintenance.api.v1beta.Maintenance/SummarizeMaintenances",
355
+ request_serializer=maintenance_service.SummarizeMaintenancesRequest.serialize,
356
+ response_deserializer=maintenance_service.SummarizeMaintenancesResponse.deserialize,
357
+ )
358
+ return self._stubs["summarize_maintenances"]
359
+
360
+ @property
361
+ def list_resource_maintenances(
362
+ self,
363
+ ) -> Callable[
364
+ [maintenance_service.ListResourceMaintenancesRequest],
365
+ Awaitable[maintenance_service.ListResourceMaintenancesResponse],
366
+ ]:
367
+ r"""Return a callable for the list resource maintenances method over gRPC.
368
+
369
+ Retrieve a collection of resource maintenances.
370
+
371
+ Returns:
372
+ Callable[[~.ListResourceMaintenancesRequest],
373
+ Awaitable[~.ListResourceMaintenancesResponse]]:
374
+ A function that, when called, will call the underlying RPC
375
+ on the server.
376
+ """
377
+ # Generate a "stub function" on-the-fly which will actually make
378
+ # the request.
379
+ # gRPC handles serialization and deserialization, so we just need
380
+ # to pass in the functions for each.
381
+ if "list_resource_maintenances" not in self._stubs:
382
+ self._stubs[
383
+ "list_resource_maintenances"
384
+ ] = self._logged_channel.unary_unary(
385
+ "/google.cloud.maintenance.api.v1beta.Maintenance/ListResourceMaintenances",
386
+ request_serializer=maintenance_service.ListResourceMaintenancesRequest.serialize,
387
+ response_deserializer=maintenance_service.ListResourceMaintenancesResponse.deserialize,
388
+ )
389
+ return self._stubs["list_resource_maintenances"]
390
+
391
+ @property
392
+ def get_resource_maintenance(
393
+ self,
394
+ ) -> Callable[
395
+ [maintenance_service.GetResourceMaintenanceRequest],
396
+ Awaitable[maintenance_service.ResourceMaintenance],
397
+ ]:
398
+ r"""Return a callable for the get resource maintenance method over gRPC.
399
+
400
+ Retrieve a single resource maintenance.
401
+
402
+ Returns:
403
+ Callable[[~.GetResourceMaintenanceRequest],
404
+ Awaitable[~.ResourceMaintenance]]:
405
+ A function that, when called, will call the underlying RPC
406
+ on the server.
407
+ """
408
+ # Generate a "stub function" on-the-fly which will actually make
409
+ # the request.
410
+ # gRPC handles serialization and deserialization, so we just need
411
+ # to pass in the functions for each.
412
+ if "get_resource_maintenance" not in self._stubs:
413
+ self._stubs["get_resource_maintenance"] = self._logged_channel.unary_unary(
414
+ "/google.cloud.maintenance.api.v1beta.Maintenance/GetResourceMaintenance",
415
+ request_serializer=maintenance_service.GetResourceMaintenanceRequest.serialize,
416
+ response_deserializer=maintenance_service.ResourceMaintenance.deserialize,
417
+ )
418
+ return self._stubs["get_resource_maintenance"]
419
+
420
+ def _prep_wrapped_messages(self, client_info):
421
+ """Precompute the wrapped methods, overriding the base class method to use async wrappers."""
422
+ self._wrapped_methods = {
423
+ self.summarize_maintenances: self._wrap_method(
424
+ self.summarize_maintenances,
425
+ default_timeout=None,
426
+ client_info=client_info,
427
+ ),
428
+ self.list_resource_maintenances: self._wrap_method(
429
+ self.list_resource_maintenances,
430
+ default_timeout=None,
431
+ client_info=client_info,
432
+ ),
433
+ self.get_resource_maintenance: self._wrap_method(
434
+ self.get_resource_maintenance,
435
+ default_timeout=None,
436
+ client_info=client_info,
437
+ ),
438
+ self.get_location: self._wrap_method(
439
+ self.get_location,
440
+ default_timeout=None,
441
+ client_info=client_info,
442
+ ),
443
+ self.list_locations: self._wrap_method(
444
+ self.list_locations,
445
+ default_timeout=None,
446
+ client_info=client_info,
447
+ ),
448
+ }
449
+
450
+ def _wrap_method(self, func, *args, **kwargs):
451
+ if self._wrap_with_kind: # pragma: NO COVER
452
+ kwargs["kind"] = self.kind
453
+ return gapic_v1.method_async.wrap_method(func, *args, **kwargs)
454
+
455
+ def close(self):
456
+ return self._logged_channel.close()
457
+
458
+ @property
459
+ def kind(self) -> str:
460
+ return "grpc_asyncio"
461
+
462
+ @property
463
+ def list_locations(
464
+ self,
465
+ ) -> Callable[
466
+ [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse
467
+ ]:
468
+ r"""Return a callable for the list locations method over gRPC."""
469
+ # Generate a "stub function" on-the-fly which will actually make
470
+ # the request.
471
+ # gRPC handles serialization and deserialization, so we just need
472
+ # to pass in the functions for each.
473
+ if "list_locations" not in self._stubs:
474
+ self._stubs["list_locations"] = self._logged_channel.unary_unary(
475
+ "/google.cloud.location.Locations/ListLocations",
476
+ request_serializer=locations_pb2.ListLocationsRequest.SerializeToString,
477
+ response_deserializer=locations_pb2.ListLocationsResponse.FromString,
478
+ )
479
+ return self._stubs["list_locations"]
480
+
481
+ @property
482
+ def get_location(
483
+ self,
484
+ ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]:
485
+ r"""Return a callable for the list locations method over gRPC."""
486
+ # Generate a "stub function" on-the-fly which will actually make
487
+ # the request.
488
+ # gRPC handles serialization and deserialization, so we just need
489
+ # to pass in the functions for each.
490
+ if "get_location" not in self._stubs:
491
+ self._stubs["get_location"] = self._logged_channel.unary_unary(
492
+ "/google.cloud.location.Locations/GetLocation",
493
+ request_serializer=locations_pb2.GetLocationRequest.SerializeToString,
494
+ response_deserializer=locations_pb2.Location.FromString,
495
+ )
496
+ return self._stubs["get_location"]
497
+
498
+
499
+ __all__ = ("MaintenanceGrpcAsyncIOTransport",)