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