google-cloud-cloudcontrolspartner 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 (76) hide show
  1. google/cloud/cloudcontrolspartner/__init__.py +115 -0
  2. google/cloud/cloudcontrolspartner/gapic_version.py +16 -0
  3. google/cloud/cloudcontrolspartner/py.typed +2 -0
  4. google/cloud/cloudcontrolspartner_v1/__init__.py +103 -0
  5. google/cloud/cloudcontrolspartner_v1/gapic_metadata.json +197 -0
  6. google/cloud/cloudcontrolspartner_v1/gapic_version.py +16 -0
  7. google/cloud/cloudcontrolspartner_v1/py.typed +2 -0
  8. google/cloud/cloudcontrolspartner_v1/services/__init__.py +15 -0
  9. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/__init__.py +22 -0
  10. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/async_client.py +1253 -0
  11. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/client.py +1705 -0
  12. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/pagers.py +429 -0
  13. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/__init__.py +41 -0
  14. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/base.py +340 -0
  15. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/grpc.py +466 -0
  16. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/grpc_asyncio.py +472 -0
  17. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_core/transports/rest.py +1212 -0
  18. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/__init__.py +22 -0
  19. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/async_client.py +528 -0
  20. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/client.py +935 -0
  21. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/pagers.py +155 -0
  22. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/__init__.py +41 -0
  23. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/base.py +194 -0
  24. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/grpc.py +300 -0
  25. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/grpc_asyncio.py +299 -0
  26. google/cloud/cloudcontrolspartner_v1/services/cloud_controls_partner_monitoring/transports/rest.py +434 -0
  27. google/cloud/cloudcontrolspartner_v1/types/__init__.py +82 -0
  28. google/cloud/cloudcontrolspartner_v1/types/access_approval_requests.py +228 -0
  29. google/cloud/cloudcontrolspartner_v1/types/completion_state.py +53 -0
  30. google/cloud/cloudcontrolspartner_v1/types/core.py +93 -0
  31. google/cloud/cloudcontrolspartner_v1/types/customer_workloads.py +300 -0
  32. google/cloud/cloudcontrolspartner_v1/types/customers.py +233 -0
  33. google/cloud/cloudcontrolspartner_v1/types/ekm_connections.py +141 -0
  34. google/cloud/cloudcontrolspartner_v1/types/monitoring.py +24 -0
  35. google/cloud/cloudcontrolspartner_v1/types/partner_permissions.py +94 -0
  36. google/cloud/cloudcontrolspartner_v1/types/partners.py +188 -0
  37. google/cloud/cloudcontrolspartner_v1/types/violations.py +388 -0
  38. google/cloud/cloudcontrolspartner_v1beta/__init__.py +103 -0
  39. google/cloud/cloudcontrolspartner_v1beta/gapic_metadata.json +197 -0
  40. google/cloud/cloudcontrolspartner_v1beta/gapic_version.py +16 -0
  41. google/cloud/cloudcontrolspartner_v1beta/py.typed +2 -0
  42. google/cloud/cloudcontrolspartner_v1beta/services/__init__.py +15 -0
  43. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/__init__.py +22 -0
  44. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/async_client.py +1262 -0
  45. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/client.py +1714 -0
  46. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/pagers.py +429 -0
  47. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/__init__.py +41 -0
  48. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/base.py +340 -0
  49. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/grpc.py +466 -0
  50. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/grpc_asyncio.py +472 -0
  51. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_core/transports/rest.py +1212 -0
  52. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/__init__.py +22 -0
  53. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/async_client.py +530 -0
  54. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/client.py +937 -0
  55. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/pagers.py +155 -0
  56. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/__init__.py +41 -0
  57. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/base.py +194 -0
  58. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/grpc.py +300 -0
  59. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/grpc_asyncio.py +299 -0
  60. google/cloud/cloudcontrolspartner_v1beta/services/cloud_controls_partner_monitoring/transports/rest.py +434 -0
  61. google/cloud/cloudcontrolspartner_v1beta/types/__init__.py +82 -0
  62. google/cloud/cloudcontrolspartner_v1beta/types/access_approval_requests.py +230 -0
  63. google/cloud/cloudcontrolspartner_v1beta/types/completion_state.py +53 -0
  64. google/cloud/cloudcontrolspartner_v1beta/types/core.py +93 -0
  65. google/cloud/cloudcontrolspartner_v1beta/types/customer_workloads.py +304 -0
  66. google/cloud/cloudcontrolspartner_v1beta/types/customers.py +236 -0
  67. google/cloud/cloudcontrolspartner_v1beta/types/ekm_connections.py +143 -0
  68. google/cloud/cloudcontrolspartner_v1beta/types/monitoring.py +24 -0
  69. google/cloud/cloudcontrolspartner_v1beta/types/partner_permissions.py +96 -0
  70. google/cloud/cloudcontrolspartner_v1beta/types/partners.py +189 -0
  71. google/cloud/cloudcontrolspartner_v1beta/types/violations.py +391 -0
  72. google_cloud_cloudcontrolspartner-0.1.0.dist-info/LICENSE +202 -0
  73. google_cloud_cloudcontrolspartner-0.1.0.dist-info/METADATA +137 -0
  74. google_cloud_cloudcontrolspartner-0.1.0.dist-info/RECORD +76 -0
  75. google_cloud_cloudcontrolspartner-0.1.0.dist-info/WHEEL +5 -0
  76. google_cloud_cloudcontrolspartner-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,935 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2023 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
+ from collections import OrderedDict
17
+ import os
18
+ import re
19
+ from typing import (
20
+ Dict,
21
+ Mapping,
22
+ MutableMapping,
23
+ MutableSequence,
24
+ Optional,
25
+ Sequence,
26
+ Tuple,
27
+ Type,
28
+ Union,
29
+ cast,
30
+ )
31
+ import warnings
32
+
33
+ from google.api_core import client_options as client_options_lib
34
+ from google.api_core import exceptions as core_exceptions
35
+ from google.api_core import gapic_v1
36
+ from google.api_core import retry as retries
37
+ from google.auth import credentials as ga_credentials # type: ignore
38
+ from google.auth.exceptions import MutualTLSChannelError # type: ignore
39
+ from google.auth.transport import mtls # type: ignore
40
+ from google.auth.transport.grpc import SslCredentials # type: ignore
41
+ from google.oauth2 import service_account # type: ignore
42
+
43
+ from google.cloud.cloudcontrolspartner_v1 import gapic_version as package_version
44
+
45
+ try:
46
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
47
+ except AttributeError: # pragma: NO COVER
48
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
49
+
50
+ from google.protobuf import timestamp_pb2 # type: ignore
51
+
52
+ from google.cloud.cloudcontrolspartner_v1.services.cloud_controls_partner_monitoring import (
53
+ pagers,
54
+ )
55
+ from google.cloud.cloudcontrolspartner_v1.types import violations
56
+
57
+ from .transports.base import (
58
+ DEFAULT_CLIENT_INFO,
59
+ CloudControlsPartnerMonitoringTransport,
60
+ )
61
+ from .transports.grpc import CloudControlsPartnerMonitoringGrpcTransport
62
+ from .transports.grpc_asyncio import CloudControlsPartnerMonitoringGrpcAsyncIOTransport
63
+ from .transports.rest import CloudControlsPartnerMonitoringRestTransport
64
+
65
+
66
+ class CloudControlsPartnerMonitoringClientMeta(type):
67
+ """Metaclass for the CloudControlsPartnerMonitoring client.
68
+
69
+ This provides class-level methods for building and retrieving
70
+ support objects (e.g. transport) without polluting the client instance
71
+ objects.
72
+ """
73
+
74
+ _transport_registry = (
75
+ OrderedDict()
76
+ ) # type: Dict[str, Type[CloudControlsPartnerMonitoringTransport]]
77
+ _transport_registry["grpc"] = CloudControlsPartnerMonitoringGrpcTransport
78
+ _transport_registry[
79
+ "grpc_asyncio"
80
+ ] = CloudControlsPartnerMonitoringGrpcAsyncIOTransport
81
+ _transport_registry["rest"] = CloudControlsPartnerMonitoringRestTransport
82
+
83
+ def get_transport_class(
84
+ cls,
85
+ label: Optional[str] = None,
86
+ ) -> Type[CloudControlsPartnerMonitoringTransport]:
87
+ """Returns an appropriate transport class.
88
+
89
+ Args:
90
+ label: The name of the desired transport. If none is
91
+ provided, then the first transport in the registry is used.
92
+
93
+ Returns:
94
+ The transport class to use.
95
+ """
96
+ # If a specific transport is requested, return that one.
97
+ if label:
98
+ return cls._transport_registry[label]
99
+
100
+ # No transport is requested; return the default (that is, the first one
101
+ # in the dictionary).
102
+ return next(iter(cls._transport_registry.values()))
103
+
104
+
105
+ class CloudControlsPartnerMonitoringClient(
106
+ metaclass=CloudControlsPartnerMonitoringClientMeta
107
+ ):
108
+ """Service describing handlers for resources"""
109
+
110
+ @staticmethod
111
+ def _get_default_mtls_endpoint(api_endpoint):
112
+ """Converts api endpoint to mTLS endpoint.
113
+
114
+ Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
115
+ "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
116
+ Args:
117
+ api_endpoint (Optional[str]): the api endpoint to convert.
118
+ Returns:
119
+ str: converted mTLS api endpoint.
120
+ """
121
+ if not api_endpoint:
122
+ return api_endpoint
123
+
124
+ mtls_endpoint_re = re.compile(
125
+ r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
126
+ )
127
+
128
+ m = mtls_endpoint_re.match(api_endpoint)
129
+ name, mtls, sandbox, googledomain = m.groups()
130
+ if mtls or not googledomain:
131
+ return api_endpoint
132
+
133
+ if sandbox:
134
+ return api_endpoint.replace(
135
+ "sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
136
+ )
137
+
138
+ return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
139
+
140
+ # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
141
+ DEFAULT_ENDPOINT = "cloudcontrolspartner.googleapis.com"
142
+ DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
143
+ DEFAULT_ENDPOINT
144
+ )
145
+
146
+ _DEFAULT_ENDPOINT_TEMPLATE = "cloudcontrolspartner.{UNIVERSE_DOMAIN}"
147
+ _DEFAULT_UNIVERSE = "googleapis.com"
148
+
149
+ @classmethod
150
+ def from_service_account_info(cls, info: dict, *args, **kwargs):
151
+ """Creates an instance of this client using the provided credentials
152
+ info.
153
+
154
+ Args:
155
+ info (dict): The service account private key info.
156
+ args: Additional arguments to pass to the constructor.
157
+ kwargs: Additional arguments to pass to the constructor.
158
+
159
+ Returns:
160
+ CloudControlsPartnerMonitoringClient: The constructed client.
161
+ """
162
+ credentials = service_account.Credentials.from_service_account_info(info)
163
+ kwargs["credentials"] = credentials
164
+ return cls(*args, **kwargs)
165
+
166
+ @classmethod
167
+ def from_service_account_file(cls, filename: str, *args, **kwargs):
168
+ """Creates an instance of this client using the provided credentials
169
+ file.
170
+
171
+ Args:
172
+ filename (str): The path to the service account private key json
173
+ file.
174
+ args: Additional arguments to pass to the constructor.
175
+ kwargs: Additional arguments to pass to the constructor.
176
+
177
+ Returns:
178
+ CloudControlsPartnerMonitoringClient: The constructed client.
179
+ """
180
+ credentials = service_account.Credentials.from_service_account_file(filename)
181
+ kwargs["credentials"] = credentials
182
+ return cls(*args, **kwargs)
183
+
184
+ from_service_account_json = from_service_account_file
185
+
186
+ @property
187
+ def transport(self) -> CloudControlsPartnerMonitoringTransport:
188
+ """Returns the transport used by the client instance.
189
+
190
+ Returns:
191
+ CloudControlsPartnerMonitoringTransport: The transport used by the client
192
+ instance.
193
+ """
194
+ return self._transport
195
+
196
+ @staticmethod
197
+ def violation_path(
198
+ organization: str,
199
+ location: str,
200
+ customer: str,
201
+ workload: str,
202
+ violation: str,
203
+ ) -> str:
204
+ """Returns a fully-qualified violation string."""
205
+ return "organizations/{organization}/locations/{location}/customers/{customer}/workloads/{workload}/violations/{violation}".format(
206
+ organization=organization,
207
+ location=location,
208
+ customer=customer,
209
+ workload=workload,
210
+ violation=violation,
211
+ )
212
+
213
+ @staticmethod
214
+ def parse_violation_path(path: str) -> Dict[str, str]:
215
+ """Parses a violation path into its component segments."""
216
+ m = re.match(
217
+ r"^organizations/(?P<organization>.+?)/locations/(?P<location>.+?)/customers/(?P<customer>.+?)/workloads/(?P<workload>.+?)/violations/(?P<violation>.+?)$",
218
+ path,
219
+ )
220
+ return m.groupdict() if m else {}
221
+
222
+ @staticmethod
223
+ def common_billing_account_path(
224
+ billing_account: str,
225
+ ) -> str:
226
+ """Returns a fully-qualified billing_account string."""
227
+ return "billingAccounts/{billing_account}".format(
228
+ billing_account=billing_account,
229
+ )
230
+
231
+ @staticmethod
232
+ def parse_common_billing_account_path(path: str) -> Dict[str, str]:
233
+ """Parse a billing_account path into its component segments."""
234
+ m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
235
+ return m.groupdict() if m else {}
236
+
237
+ @staticmethod
238
+ def common_folder_path(
239
+ folder: str,
240
+ ) -> str:
241
+ """Returns a fully-qualified folder string."""
242
+ return "folders/{folder}".format(
243
+ folder=folder,
244
+ )
245
+
246
+ @staticmethod
247
+ def parse_common_folder_path(path: str) -> Dict[str, str]:
248
+ """Parse a folder path into its component segments."""
249
+ m = re.match(r"^folders/(?P<folder>.+?)$", path)
250
+ return m.groupdict() if m else {}
251
+
252
+ @staticmethod
253
+ def common_organization_path(
254
+ organization: str,
255
+ ) -> str:
256
+ """Returns a fully-qualified organization string."""
257
+ return "organizations/{organization}".format(
258
+ organization=organization,
259
+ )
260
+
261
+ @staticmethod
262
+ def parse_common_organization_path(path: str) -> Dict[str, str]:
263
+ """Parse a organization path into its component segments."""
264
+ m = re.match(r"^organizations/(?P<organization>.+?)$", path)
265
+ return m.groupdict() if m else {}
266
+
267
+ @staticmethod
268
+ def common_project_path(
269
+ project: str,
270
+ ) -> str:
271
+ """Returns a fully-qualified project string."""
272
+ return "projects/{project}".format(
273
+ project=project,
274
+ )
275
+
276
+ @staticmethod
277
+ def parse_common_project_path(path: str) -> Dict[str, str]:
278
+ """Parse a project path into its component segments."""
279
+ m = re.match(r"^projects/(?P<project>.+?)$", path)
280
+ return m.groupdict() if m else {}
281
+
282
+ @staticmethod
283
+ def common_location_path(
284
+ project: str,
285
+ location: str,
286
+ ) -> str:
287
+ """Returns a fully-qualified location string."""
288
+ return "projects/{project}/locations/{location}".format(
289
+ project=project,
290
+ location=location,
291
+ )
292
+
293
+ @staticmethod
294
+ def parse_common_location_path(path: str) -> Dict[str, str]:
295
+ """Parse a location path into its component segments."""
296
+ m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
297
+ return m.groupdict() if m else {}
298
+
299
+ @classmethod
300
+ def get_mtls_endpoint_and_cert_source(
301
+ cls, client_options: Optional[client_options_lib.ClientOptions] = None
302
+ ):
303
+ """Deprecated. Return the API endpoint and client cert source for mutual TLS.
304
+
305
+ The client cert source is determined in the following order:
306
+ (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
307
+ client cert source is None.
308
+ (2) if `client_options.client_cert_source` is provided, use the provided one; if the
309
+ default client cert source exists, use the default one; otherwise the client cert
310
+ source is None.
311
+
312
+ The API endpoint is determined in the following order:
313
+ (1) if `client_options.api_endpoint` if provided, use the provided one.
314
+ (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
315
+ default mTLS endpoint; if the environment variable is "never", use the default API
316
+ endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
317
+ use the default API endpoint.
318
+
319
+ More details can be found at https://google.aip.dev/auth/4114.
320
+
321
+ Args:
322
+ client_options (google.api_core.client_options.ClientOptions): Custom options for the
323
+ client. Only the `api_endpoint` and `client_cert_source` properties may be used
324
+ in this method.
325
+
326
+ Returns:
327
+ Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
328
+ client cert source to use.
329
+
330
+ Raises:
331
+ google.auth.exceptions.MutualTLSChannelError: If any errors happen.
332
+ """
333
+
334
+ warnings.warn(
335
+ "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.",
336
+ DeprecationWarning,
337
+ )
338
+ if client_options is None:
339
+ client_options = client_options_lib.ClientOptions()
340
+ use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
341
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
342
+ if use_client_cert not in ("true", "false"):
343
+ raise ValueError(
344
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
345
+ )
346
+ if use_mtls_endpoint not in ("auto", "never", "always"):
347
+ raise MutualTLSChannelError(
348
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
349
+ )
350
+
351
+ # Figure out the client cert source to use.
352
+ client_cert_source = None
353
+ if use_client_cert == "true":
354
+ if client_options.client_cert_source:
355
+ client_cert_source = client_options.client_cert_source
356
+ elif mtls.has_default_client_cert_source():
357
+ client_cert_source = mtls.default_client_cert_source()
358
+
359
+ # Figure out which api endpoint to use.
360
+ if client_options.api_endpoint is not None:
361
+ api_endpoint = client_options.api_endpoint
362
+ elif use_mtls_endpoint == "always" or (
363
+ use_mtls_endpoint == "auto" and client_cert_source
364
+ ):
365
+ api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
366
+ else:
367
+ api_endpoint = cls.DEFAULT_ENDPOINT
368
+
369
+ return api_endpoint, client_cert_source
370
+
371
+ @staticmethod
372
+ def _read_environment_variables():
373
+ """Returns the environment variables used by the client.
374
+
375
+ Returns:
376
+ Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE,
377
+ GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables.
378
+
379
+ Raises:
380
+ ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not
381
+ any of ["true", "false"].
382
+ google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
383
+ is not any of ["auto", "never", "always"].
384
+ """
385
+ use_client_cert = os.getenv(
386
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
387
+ ).lower()
388
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
389
+ universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
390
+ if use_client_cert not in ("true", "false"):
391
+ raise ValueError(
392
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
393
+ )
394
+ if use_mtls_endpoint not in ("auto", "never", "always"):
395
+ raise MutualTLSChannelError(
396
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
397
+ )
398
+ return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
399
+
400
+ @staticmethod
401
+ def _get_client_cert_source(provided_cert_source, use_cert_flag):
402
+ """Return the client cert source to be used by the client.
403
+
404
+ Args:
405
+ provided_cert_source (bytes): The client certificate source provided.
406
+ use_cert_flag (bool): A flag indicating whether to use the client certificate.
407
+
408
+ Returns:
409
+ bytes or None: The client cert source to be used by the client.
410
+ """
411
+ client_cert_source = None
412
+ if use_cert_flag:
413
+ if provided_cert_source:
414
+ client_cert_source = provided_cert_source
415
+ elif mtls.has_default_client_cert_source():
416
+ client_cert_source = mtls.default_client_cert_source()
417
+ return client_cert_source
418
+
419
+ @staticmethod
420
+ def _get_api_endpoint(
421
+ api_override, client_cert_source, universe_domain, use_mtls_endpoint
422
+ ):
423
+ """Return the API endpoint used by the client.
424
+
425
+ Args:
426
+ api_override (str): The API endpoint override. If specified, this is always
427
+ the return value of this function and the other arguments are not used.
428
+ client_cert_source (bytes): The client certificate source used by the client.
429
+ universe_domain (str): The universe domain used by the client.
430
+ use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
431
+ Possible values are "always", "auto", or "never".
432
+
433
+ Returns:
434
+ str: The API endpoint to be used by the client.
435
+ """
436
+ if api_override is not None:
437
+ api_endpoint = api_override
438
+ elif use_mtls_endpoint == "always" or (
439
+ use_mtls_endpoint == "auto" and client_cert_source
440
+ ):
441
+ _default_universe = CloudControlsPartnerMonitoringClient._DEFAULT_UNIVERSE
442
+ if universe_domain != _default_universe:
443
+ raise MutualTLSChannelError(
444
+ f"mTLS is not supported in any universe other than {_default_universe}."
445
+ )
446
+ api_endpoint = CloudControlsPartnerMonitoringClient.DEFAULT_MTLS_ENDPOINT
447
+ else:
448
+ api_endpoint = (
449
+ CloudControlsPartnerMonitoringClient._DEFAULT_ENDPOINT_TEMPLATE.format(
450
+ UNIVERSE_DOMAIN=universe_domain
451
+ )
452
+ )
453
+ return api_endpoint
454
+
455
+ @staticmethod
456
+ def _get_universe_domain(
457
+ client_universe_domain: Optional[str], universe_domain_env: Optional[str]
458
+ ) -> str:
459
+ """Return the universe domain used by the client.
460
+
461
+ Args:
462
+ client_universe_domain (Optional[str]): The universe domain configured via the client options.
463
+ universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
464
+
465
+ Returns:
466
+ str: The universe domain to be used by the client.
467
+
468
+ Raises:
469
+ ValueError: If the universe domain is an empty string.
470
+ """
471
+ universe_domain = CloudControlsPartnerMonitoringClient._DEFAULT_UNIVERSE
472
+ if client_universe_domain is not None:
473
+ universe_domain = client_universe_domain
474
+ elif universe_domain_env is not None:
475
+ universe_domain = universe_domain_env
476
+ if len(universe_domain.strip()) == 0:
477
+ raise ValueError("Universe Domain cannot be an empty string.")
478
+ return universe_domain
479
+
480
+ @staticmethod
481
+ def _compare_universes(
482
+ client_universe: str, credentials: ga_credentials.Credentials
483
+ ) -> bool:
484
+ """Returns True iff the universe domains used by the client and credentials match.
485
+
486
+ Args:
487
+ client_universe (str): The universe domain configured via the client options.
488
+ credentials (ga_credentials.Credentials): The credentials being used in the client.
489
+
490
+ Returns:
491
+ bool: True iff client_universe matches the universe in credentials.
492
+
493
+ Raises:
494
+ ValueError: when client_universe does not match the universe in credentials.
495
+ """
496
+
497
+ default_universe = CloudControlsPartnerMonitoringClient._DEFAULT_UNIVERSE
498
+ credentials_universe = getattr(credentials, "universe_domain", default_universe)
499
+
500
+ if client_universe != credentials_universe:
501
+ raise ValueError(
502
+ "The configured universe domain "
503
+ f"({client_universe}) does not match the universe domain "
504
+ f"found in the credentials ({credentials_universe}). "
505
+ "If you haven't configured the universe domain explicitly, "
506
+ f"`{default_universe}` is the default."
507
+ )
508
+ return True
509
+
510
+ def _validate_universe_domain(self):
511
+ """Validates client's and credentials' universe domains are consistent.
512
+
513
+ Returns:
514
+ bool: True iff the configured universe domain is valid.
515
+
516
+ Raises:
517
+ ValueError: If the configured universe domain is not valid.
518
+ """
519
+ self._is_universe_domain_valid = (
520
+ self._is_universe_domain_valid
521
+ or CloudControlsPartnerMonitoringClient._compare_universes(
522
+ self.universe_domain, self.transport._credentials
523
+ )
524
+ )
525
+ return self._is_universe_domain_valid
526
+
527
+ @property
528
+ def api_endpoint(self):
529
+ """Return the API endpoint used by the client instance.
530
+
531
+ Returns:
532
+ str: The API endpoint used by the client instance.
533
+ """
534
+ return self._api_endpoint
535
+
536
+ @property
537
+ def universe_domain(self) -> str:
538
+ """Return the universe domain used by the client instance.
539
+
540
+ Returns:
541
+ str: The universe domain used by the client instance.
542
+ """
543
+ return self._universe_domain
544
+
545
+ def __init__(
546
+ self,
547
+ *,
548
+ credentials: Optional[ga_credentials.Credentials] = None,
549
+ transport: Optional[Union[str, CloudControlsPartnerMonitoringTransport]] = None,
550
+ client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
551
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
552
+ ) -> None:
553
+ """Instantiates the cloud controls partner monitoring client.
554
+
555
+ Args:
556
+ credentials (Optional[google.auth.credentials.Credentials]): The
557
+ authorization credentials to attach to requests. These
558
+ credentials identify the application to the service; if none
559
+ are specified, the client will attempt to ascertain the
560
+ credentials from the environment.
561
+ transport (Union[str, CloudControlsPartnerMonitoringTransport]): The
562
+ transport to use. If set to None, a transport is chosen
563
+ automatically.
564
+ client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
565
+ Custom options for the client.
566
+
567
+ 1. The ``api_endpoint`` property can be used to override the
568
+ default endpoint provided by the client when ``transport`` is
569
+ not explicitly provided. Only if this property is not set and
570
+ ``transport`` was not explicitly provided, the endpoint is
571
+ determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
572
+ variable, which have one of the following values:
573
+ "always" (always use the default mTLS endpoint), "never" (always
574
+ use the default regular endpoint) and "auto" (auto-switch to the
575
+ default mTLS endpoint if client certificate is present; this is
576
+ the default value).
577
+
578
+ 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
579
+ is "true", then the ``client_cert_source`` property can be used
580
+ to provide a client certificate for mTLS transport. If
581
+ not provided, the default SSL client certificate will be used if
582
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
583
+ set, no client certificate will be used.
584
+
585
+ 3. The ``universe_domain`` property can be used to override the
586
+ default "googleapis.com" universe. Note that the ``api_endpoint``
587
+ property still takes precedence; and ``universe_domain`` is
588
+ currently not supported for mTLS.
589
+
590
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
591
+ The client info used to send a user-agent string along with
592
+ API requests. If ``None``, then default info will be used.
593
+ Generally, you only need to set this if you're developing
594
+ your own client library.
595
+
596
+ Raises:
597
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
598
+ creation failed for any reason.
599
+ """
600
+ self._client_options = client_options
601
+ if isinstance(self._client_options, dict):
602
+ self._client_options = client_options_lib.from_dict(self._client_options)
603
+ if self._client_options is None:
604
+ self._client_options = client_options_lib.ClientOptions()
605
+ self._client_options = cast(
606
+ client_options_lib.ClientOptions, self._client_options
607
+ )
608
+
609
+ universe_domain_opt = getattr(self._client_options, "universe_domain", None)
610
+
611
+ (
612
+ self._use_client_cert,
613
+ self._use_mtls_endpoint,
614
+ self._universe_domain_env,
615
+ ) = CloudControlsPartnerMonitoringClient._read_environment_variables()
616
+ self._client_cert_source = (
617
+ CloudControlsPartnerMonitoringClient._get_client_cert_source(
618
+ self._client_options.client_cert_source, self._use_client_cert
619
+ )
620
+ )
621
+ self._universe_domain = (
622
+ CloudControlsPartnerMonitoringClient._get_universe_domain(
623
+ universe_domain_opt, self._universe_domain_env
624
+ )
625
+ )
626
+ self._api_endpoint = None # updated below, depending on `transport`
627
+
628
+ # Initialize the universe domain validation.
629
+ self._is_universe_domain_valid = False
630
+
631
+ api_key_value = getattr(self._client_options, "api_key", None)
632
+ if api_key_value and credentials:
633
+ raise ValueError(
634
+ "client_options.api_key and credentials are mutually exclusive"
635
+ )
636
+
637
+ # Save or instantiate the transport.
638
+ # Ordinarily, we provide the transport, but allowing a custom transport
639
+ # instance provides an extensibility point for unusual situations.
640
+ transport_provided = isinstance(
641
+ transport, CloudControlsPartnerMonitoringTransport
642
+ )
643
+ if transport_provided:
644
+ # transport is a CloudControlsPartnerMonitoringTransport instance.
645
+ if credentials or self._client_options.credentials_file or api_key_value:
646
+ raise ValueError(
647
+ "When providing a transport instance, "
648
+ "provide its credentials directly."
649
+ )
650
+ if self._client_options.scopes:
651
+ raise ValueError(
652
+ "When providing a transport instance, provide its scopes "
653
+ "directly."
654
+ )
655
+ self._transport = cast(CloudControlsPartnerMonitoringTransport, transport)
656
+ self._api_endpoint = self._transport.host
657
+
658
+ self._api_endpoint = (
659
+ self._api_endpoint
660
+ or CloudControlsPartnerMonitoringClient._get_api_endpoint(
661
+ self._client_options.api_endpoint,
662
+ self._client_cert_source,
663
+ self._universe_domain,
664
+ self._use_mtls_endpoint,
665
+ )
666
+ )
667
+
668
+ if not transport_provided:
669
+ import google.auth._default # type: ignore
670
+
671
+ if api_key_value and hasattr(
672
+ google.auth._default, "get_api_key_credentials"
673
+ ):
674
+ credentials = google.auth._default.get_api_key_credentials(
675
+ api_key_value
676
+ )
677
+
678
+ Transport = type(self).get_transport_class(cast(str, transport))
679
+ self._transport = Transport(
680
+ credentials=credentials,
681
+ credentials_file=self._client_options.credentials_file,
682
+ host=self._api_endpoint,
683
+ scopes=self._client_options.scopes,
684
+ client_cert_source_for_mtls=self._client_cert_source,
685
+ quota_project_id=self._client_options.quota_project_id,
686
+ client_info=client_info,
687
+ always_use_jwt_access=True,
688
+ api_audience=self._client_options.api_audience,
689
+ )
690
+
691
+ def list_violations(
692
+ self,
693
+ request: Optional[Union[violations.ListViolationsRequest, dict]] = None,
694
+ *,
695
+ parent: Optional[str] = None,
696
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
697
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
698
+ metadata: Sequence[Tuple[str, str]] = (),
699
+ ) -> pagers.ListViolationsPager:
700
+ r"""Lists Violations for a workload Callers may also choose to read
701
+ across multiple Customers or for a single customer as per
702
+ `AIP-159 <https://google.aip.dev/159>`__ by using '-' (the
703
+ hyphen or dash character) as a wildcard character instead of
704
+ {customer} & {workload}. Format:
705
+ ``organizations/{organization}/locations/{location}/customers/{customer}/workloads/{workload}``
706
+
707
+ .. code-block:: python
708
+
709
+ # This snippet has been automatically generated and should be regarded as a
710
+ # code template only.
711
+ # It will require modifications to work:
712
+ # - It may require correct/in-range values for request initialization.
713
+ # - It may require specifying regional endpoints when creating the service
714
+ # client as shown in:
715
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
716
+ from google.cloud import cloudcontrolspartner_v1
717
+
718
+ def sample_list_violations():
719
+ # Create a client
720
+ client = cloudcontrolspartner_v1.CloudControlsPartnerMonitoringClient()
721
+
722
+ # Initialize request argument(s)
723
+ request = cloudcontrolspartner_v1.ListViolationsRequest(
724
+ parent="parent_value",
725
+ )
726
+
727
+ # Make the request
728
+ page_result = client.list_violations(request=request)
729
+
730
+ # Handle the response
731
+ for response in page_result:
732
+ print(response)
733
+
734
+ Args:
735
+ request (Union[google.cloud.cloudcontrolspartner_v1.types.ListViolationsRequest, dict]):
736
+ The request object. Message for requesting list of
737
+ Violations
738
+ parent (str):
739
+ Required. Parent resource Format
740
+ ``organizations/{organization}/locations/{location}/customers/{customer}/workloads/{workload}``
741
+
742
+ This corresponds to the ``parent`` field
743
+ on the ``request`` instance; if ``request`` is provided, this
744
+ should not be set.
745
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
746
+ should be retried.
747
+ timeout (float): The timeout for this request.
748
+ metadata (Sequence[Tuple[str, str]]): Strings which should be
749
+ sent along with the request as metadata.
750
+
751
+ Returns:
752
+ google.cloud.cloudcontrolspartner_v1.services.cloud_controls_partner_monitoring.pagers.ListViolationsPager:
753
+ Response message for list customer
754
+ violation requests
755
+ Iterating over this object will yield
756
+ results and resolve additional pages
757
+ automatically.
758
+
759
+ """
760
+ # Create or coerce a protobuf request object.
761
+ # Quick check: If we got a request object, we should *not* have
762
+ # gotten any keyword arguments that map to the request.
763
+ has_flattened_params = any([parent])
764
+ if request is not None and has_flattened_params:
765
+ raise ValueError(
766
+ "If the `request` argument is set, then none of "
767
+ "the individual field arguments should be set."
768
+ )
769
+
770
+ # Minor optimization to avoid making a copy if the user passes
771
+ # in a violations.ListViolationsRequest.
772
+ # There's no risk of modifying the input as we've already verified
773
+ # there are no flattened fields.
774
+ if not isinstance(request, violations.ListViolationsRequest):
775
+ request = violations.ListViolationsRequest(request)
776
+ # If we have keyword arguments corresponding to fields on the
777
+ # request, apply these.
778
+ if parent is not None:
779
+ request.parent = parent
780
+
781
+ # Wrap the RPC method; this adds retry and timeout information,
782
+ # and friendly error handling.
783
+ rpc = self._transport._wrapped_methods[self._transport.list_violations]
784
+
785
+ # Certain fields should be provided within the metadata header;
786
+ # add these here.
787
+ metadata = tuple(metadata) + (
788
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
789
+ )
790
+
791
+ # Validate the universe domain.
792
+ self._validate_universe_domain()
793
+
794
+ # Send the request.
795
+ response = rpc(
796
+ request,
797
+ retry=retry,
798
+ timeout=timeout,
799
+ metadata=metadata,
800
+ )
801
+
802
+ # This method is paged; wrap the response in a pager, which provides
803
+ # an `__iter__` convenience method.
804
+ response = pagers.ListViolationsPager(
805
+ method=rpc,
806
+ request=request,
807
+ response=response,
808
+ metadata=metadata,
809
+ )
810
+
811
+ # Done; return the response.
812
+ return response
813
+
814
+ def get_violation(
815
+ self,
816
+ request: Optional[Union[violations.GetViolationRequest, dict]] = None,
817
+ *,
818
+ name: Optional[str] = None,
819
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
820
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
821
+ metadata: Sequence[Tuple[str, str]] = (),
822
+ ) -> violations.Violation:
823
+ r"""Gets details of a single Violation.
824
+
825
+ .. code-block:: python
826
+
827
+ # This snippet has been automatically generated and should be regarded as a
828
+ # code template only.
829
+ # It will require modifications to work:
830
+ # - It may require correct/in-range values for request initialization.
831
+ # - It may require specifying regional endpoints when creating the service
832
+ # client as shown in:
833
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
834
+ from google.cloud import cloudcontrolspartner_v1
835
+
836
+ def sample_get_violation():
837
+ # Create a client
838
+ client = cloudcontrolspartner_v1.CloudControlsPartnerMonitoringClient()
839
+
840
+ # Initialize request argument(s)
841
+ request = cloudcontrolspartner_v1.GetViolationRequest(
842
+ name="name_value",
843
+ )
844
+
845
+ # Make the request
846
+ response = client.get_violation(request=request)
847
+
848
+ # Handle the response
849
+ print(response)
850
+
851
+ Args:
852
+ request (Union[google.cloud.cloudcontrolspartner_v1.types.GetViolationRequest, dict]):
853
+ The request object. Message for getting a Violation
854
+ name (str):
855
+ Required. Format:
856
+ ``organizations/{organization}/locations/{location}/customers/{customer}/workloads/{workload}/violations/{violation}``
857
+
858
+ This corresponds to the ``name`` field
859
+ on the ``request`` instance; if ``request`` is provided, this
860
+ should not be set.
861
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
862
+ should be retried.
863
+ timeout (float): The timeout for this request.
864
+ metadata (Sequence[Tuple[str, str]]): Strings which should be
865
+ sent along with the request as metadata.
866
+
867
+ Returns:
868
+ google.cloud.cloudcontrolspartner_v1.types.Violation:
869
+ Details of resource Violation
870
+ """
871
+ # Create or coerce a protobuf request object.
872
+ # Quick check: If we got a request object, we should *not* have
873
+ # gotten any keyword arguments that map to the request.
874
+ has_flattened_params = any([name])
875
+ if request is not None and has_flattened_params:
876
+ raise ValueError(
877
+ "If the `request` argument is set, then none of "
878
+ "the individual field arguments should be set."
879
+ )
880
+
881
+ # Minor optimization to avoid making a copy if the user passes
882
+ # in a violations.GetViolationRequest.
883
+ # There's no risk of modifying the input as we've already verified
884
+ # there are no flattened fields.
885
+ if not isinstance(request, violations.GetViolationRequest):
886
+ request = violations.GetViolationRequest(request)
887
+ # If we have keyword arguments corresponding to fields on the
888
+ # request, apply these.
889
+ if name is not None:
890
+ request.name = name
891
+
892
+ # Wrap the RPC method; this adds retry and timeout information,
893
+ # and friendly error handling.
894
+ rpc = self._transport._wrapped_methods[self._transport.get_violation]
895
+
896
+ # Certain fields should be provided within the metadata header;
897
+ # add these here.
898
+ metadata = tuple(metadata) + (
899
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
900
+ )
901
+
902
+ # Validate the universe domain.
903
+ self._validate_universe_domain()
904
+
905
+ # Send the request.
906
+ response = rpc(
907
+ request,
908
+ retry=retry,
909
+ timeout=timeout,
910
+ metadata=metadata,
911
+ )
912
+
913
+ # Done; return the response.
914
+ return response
915
+
916
+ def __enter__(self) -> "CloudControlsPartnerMonitoringClient":
917
+ return self
918
+
919
+ def __exit__(self, type, value, traceback):
920
+ """Releases underlying transport's resources.
921
+
922
+ .. warning::
923
+ ONLY use as a context manager if the transport is NOT shared
924
+ with other clients! Exiting the with block will CLOSE the transport
925
+ and may cause errors in other clients!
926
+ """
927
+ self.transport.close()
928
+
929
+
930
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
931
+ gapic_version=package_version.__version__
932
+ )
933
+
934
+
935
+ __all__ = ("CloudControlsPartnerMonitoringClient",)