google-cloud-securitycentermanagement 0.2.0__tar.gz → 0.3.0__tar.gz

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 (38) hide show
  1. {google_cloud_securitycentermanagement-0.2.0/google_cloud_securitycentermanagement.egg-info → google_cloud_securitycentermanagement-0.3.0}/PKG-INFO +1 -1
  2. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement/gapic_version.py +1 -1
  3. google_cloud_securitycentermanagement-0.3.0/google/cloud/securitycentermanagement_v1/__init__.py +209 -0
  4. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/gapic_version.py +1 -1
  5. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/security_center_management/client.py +32 -14
  6. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0/google_cloud_securitycentermanagement.egg-info}/PKG-INFO +1 -1
  7. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/tests/unit/gapic/securitycentermanagement_v1/test_security_center_management.py +228 -29
  8. google_cloud_securitycentermanagement-0.2.0/google/cloud/securitycentermanagement_v1/__init__.py +0 -105
  9. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/LICENSE +0 -0
  10. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/MANIFEST.in +0 -0
  11. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/README.rst +0 -0
  12. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement/__init__.py +0 -0
  13. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement/py.typed +0 -0
  14. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/gapic_metadata.json +0 -0
  15. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/py.typed +0 -0
  16. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/__init__.py +0 -0
  17. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/security_center_management/__init__.py +0 -0
  18. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/security_center_management/async_client.py +0 -0
  19. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/security_center_management/pagers.py +0 -0
  20. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/security_center_management/transports/__init__.py +0 -0
  21. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/security_center_management/transports/base.py +0 -0
  22. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/security_center_management/transports/grpc.py +0 -0
  23. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/security_center_management/transports/grpc_asyncio.py +0 -0
  24. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/security_center_management/transports/rest.py +0 -0
  25. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/services/security_center_management/transports/rest_base.py +0 -0
  26. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/types/__init__.py +0 -0
  27. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google/cloud/securitycentermanagement_v1/types/security_center_management.py +0 -0
  28. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google_cloud_securitycentermanagement.egg-info/SOURCES.txt +0 -0
  29. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google_cloud_securitycentermanagement.egg-info/dependency_links.txt +0 -0
  30. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google_cloud_securitycentermanagement.egg-info/not-zip-safe +0 -0
  31. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google_cloud_securitycentermanagement.egg-info/requires.txt +0 -0
  32. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/google_cloud_securitycentermanagement.egg-info/top_level.txt +0 -0
  33. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/setup.cfg +0 -0
  34. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/setup.py +0 -0
  35. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/tests/__init__.py +0 -0
  36. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/tests/unit/__init__.py +0 -0
  37. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/tests/unit/gapic/__init__.py +0 -0
  38. {google_cloud_securitycentermanagement-0.2.0 → google_cloud_securitycentermanagement-0.3.0}/tests/unit/gapic/securitycentermanagement_v1/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-cloud-securitycentermanagement
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Google Cloud Securitycentermanagement API client library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-securitycentermanagement
6
6
  Author: Google LLC
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- __version__ = "0.2.0" # {x-release-please-version}
16
+ __version__ = "0.3.0" # {x-release-please-version}
@@ -0,0 +1,209 @@
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 sys
17
+
18
+ import google.api_core as api_core
19
+
20
+ from google.cloud.securitycentermanagement_v1 import gapic_version as package_version
21
+
22
+ __version__ = package_version.__version__
23
+
24
+ if sys.version_info >= (3, 8): # pragma: NO COVER
25
+ from importlib import metadata
26
+ else: # pragma: NO COVER
27
+ # TODO(https://github.com/googleapis/python-api-core/issues/835): Remove
28
+ # this code path once we drop support for Python 3.7
29
+ import importlib_metadata as metadata
30
+
31
+ from .services.security_center_management import (
32
+ SecurityCenterManagementAsyncClient,
33
+ SecurityCenterManagementClient,
34
+ )
35
+ from .types.security_center_management import (
36
+ CreateEventThreatDetectionCustomModuleRequest,
37
+ CreateSecurityHealthAnalyticsCustomModuleRequest,
38
+ CustomConfig,
39
+ DeleteEventThreatDetectionCustomModuleRequest,
40
+ DeleteSecurityHealthAnalyticsCustomModuleRequest,
41
+ EffectiveEventThreatDetectionCustomModule,
42
+ EffectiveSecurityHealthAnalyticsCustomModule,
43
+ EventThreatDetectionCustomModule,
44
+ GetEffectiveEventThreatDetectionCustomModuleRequest,
45
+ GetEffectiveSecurityHealthAnalyticsCustomModuleRequest,
46
+ GetEventThreatDetectionCustomModuleRequest,
47
+ GetSecurityCenterServiceRequest,
48
+ GetSecurityHealthAnalyticsCustomModuleRequest,
49
+ ListDescendantEventThreatDetectionCustomModulesRequest,
50
+ ListDescendantEventThreatDetectionCustomModulesResponse,
51
+ ListDescendantSecurityHealthAnalyticsCustomModulesRequest,
52
+ ListDescendantSecurityHealthAnalyticsCustomModulesResponse,
53
+ ListEffectiveEventThreatDetectionCustomModulesRequest,
54
+ ListEffectiveEventThreatDetectionCustomModulesResponse,
55
+ ListEffectiveSecurityHealthAnalyticsCustomModulesRequest,
56
+ ListEffectiveSecurityHealthAnalyticsCustomModulesResponse,
57
+ ListEventThreatDetectionCustomModulesRequest,
58
+ ListEventThreatDetectionCustomModulesResponse,
59
+ ListSecurityCenterServicesRequest,
60
+ ListSecurityCenterServicesResponse,
61
+ ListSecurityHealthAnalyticsCustomModulesRequest,
62
+ ListSecurityHealthAnalyticsCustomModulesResponse,
63
+ SecurityCenterService,
64
+ SecurityHealthAnalyticsCustomModule,
65
+ SimulatedFinding,
66
+ SimulateSecurityHealthAnalyticsCustomModuleRequest,
67
+ SimulateSecurityHealthAnalyticsCustomModuleResponse,
68
+ UpdateEventThreatDetectionCustomModuleRequest,
69
+ UpdateSecurityCenterServiceRequest,
70
+ UpdateSecurityHealthAnalyticsCustomModuleRequest,
71
+ ValidateEventThreatDetectionCustomModuleRequest,
72
+ ValidateEventThreatDetectionCustomModuleResponse,
73
+ )
74
+
75
+ if hasattr(api_core, "check_python_version") and hasattr(
76
+ api_core, "check_dependency_versions"
77
+ ): # pragma: NO COVER
78
+ api_core.check_python_version("google.cloud.securitycentermanagement_v1") # type: ignore
79
+ api_core.check_dependency_versions("google.cloud.securitycentermanagement_v1") # type: ignore
80
+ else: # pragma: NO COVER
81
+ # An older version of api_core is installed which does not define the
82
+ # functions above. We do equivalent checks manually.
83
+ try:
84
+ import sys
85
+ import warnings
86
+
87
+ _py_version_str = sys.version.split()[0]
88
+ _package_label = "google.cloud.securitycentermanagement_v1"
89
+ if sys.version_info < (3, 9):
90
+ warnings.warn(
91
+ "You are using a non-supported Python version "
92
+ + f"({_py_version_str}). Google will not post any further "
93
+ + f"updates to {_package_label} supporting this Python version. "
94
+ + "Please upgrade to the latest Python version, or at "
95
+ + f"least to Python 3.9, and then update {_package_label}.",
96
+ FutureWarning,
97
+ )
98
+ if sys.version_info[:2] == (3, 9):
99
+ warnings.warn(
100
+ f"You are using a Python version ({_py_version_str}) "
101
+ + f"which Google will stop supporting in {_package_label} in "
102
+ + "January 2026. Please "
103
+ + "upgrade to the latest Python version, or at "
104
+ + "least to Python 3.10, before then, and "
105
+ + f"then update {_package_label}.",
106
+ FutureWarning,
107
+ )
108
+
109
+ def parse_version_to_tuple(version_string: str):
110
+ """Safely converts a semantic version string to a comparable tuple of integers.
111
+ Example: "4.25.8" -> (4, 25, 8)
112
+ Ignores non-numeric parts and handles common version formats.
113
+ Args:
114
+ version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
115
+ Returns:
116
+ Tuple of integers for the parsed version string.
117
+ """
118
+ parts = []
119
+ for part in version_string.split("."):
120
+ try:
121
+ parts.append(int(part))
122
+ except ValueError:
123
+ # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
124
+ # This is a simplification compared to 'packaging.parse_version', but sufficient
125
+ # for comparing strictly numeric semantic versions.
126
+ break
127
+ return tuple(parts)
128
+
129
+ def _get_version(dependency_name):
130
+ try:
131
+ version_string: str = metadata.version(dependency_name)
132
+ parsed_version = parse_version_to_tuple(version_string)
133
+ return (parsed_version, version_string)
134
+ except Exception:
135
+ # Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
136
+ # or errors during parse_version_to_tuple
137
+ return (None, "--")
138
+
139
+ _dependency_package = "google.protobuf"
140
+ _next_supported_version = "4.25.8"
141
+ _next_supported_version_tuple = (4, 25, 8)
142
+ _recommendation = " (we recommend 6.x)"
143
+ (_version_used, _version_used_string) = _get_version(_dependency_package)
144
+ if _version_used and _version_used < _next_supported_version_tuple:
145
+ warnings.warn(
146
+ f"Package {_package_label} depends on "
147
+ + f"{_dependency_package}, currently installed at version "
148
+ + f"{_version_used_string}. Future updates to "
149
+ + f"{_package_label} will require {_dependency_package} at "
150
+ + f"version {_next_supported_version} or higher{_recommendation}."
151
+ + " Please ensure "
152
+ + "that either (a) your Python environment doesn't pin the "
153
+ + f"version of {_dependency_package}, so that updates to "
154
+ + f"{_package_label} can require the higher version, or "
155
+ + "(b) you manually update your Python environment to use at "
156
+ + f"least version {_next_supported_version} of "
157
+ + f"{_dependency_package}.",
158
+ FutureWarning,
159
+ )
160
+ except Exception:
161
+ warnings.warn(
162
+ "Could not determine the version of Python "
163
+ + "currently being used. To continue receiving "
164
+ + "updates for {_package_label}, ensure you are "
165
+ + "using a supported version of Python; see "
166
+ + "https://devguide.python.org/versions/"
167
+ )
168
+
169
+ __all__ = (
170
+ "SecurityCenterManagementAsyncClient",
171
+ "CreateEventThreatDetectionCustomModuleRequest",
172
+ "CreateSecurityHealthAnalyticsCustomModuleRequest",
173
+ "CustomConfig",
174
+ "DeleteEventThreatDetectionCustomModuleRequest",
175
+ "DeleteSecurityHealthAnalyticsCustomModuleRequest",
176
+ "EffectiveEventThreatDetectionCustomModule",
177
+ "EffectiveSecurityHealthAnalyticsCustomModule",
178
+ "EventThreatDetectionCustomModule",
179
+ "GetEffectiveEventThreatDetectionCustomModuleRequest",
180
+ "GetEffectiveSecurityHealthAnalyticsCustomModuleRequest",
181
+ "GetEventThreatDetectionCustomModuleRequest",
182
+ "GetSecurityCenterServiceRequest",
183
+ "GetSecurityHealthAnalyticsCustomModuleRequest",
184
+ "ListDescendantEventThreatDetectionCustomModulesRequest",
185
+ "ListDescendantEventThreatDetectionCustomModulesResponse",
186
+ "ListDescendantSecurityHealthAnalyticsCustomModulesRequest",
187
+ "ListDescendantSecurityHealthAnalyticsCustomModulesResponse",
188
+ "ListEffectiveEventThreatDetectionCustomModulesRequest",
189
+ "ListEffectiveEventThreatDetectionCustomModulesResponse",
190
+ "ListEffectiveSecurityHealthAnalyticsCustomModulesRequest",
191
+ "ListEffectiveSecurityHealthAnalyticsCustomModulesResponse",
192
+ "ListEventThreatDetectionCustomModulesRequest",
193
+ "ListEventThreatDetectionCustomModulesResponse",
194
+ "ListSecurityCenterServicesRequest",
195
+ "ListSecurityCenterServicesResponse",
196
+ "ListSecurityHealthAnalyticsCustomModulesRequest",
197
+ "ListSecurityHealthAnalyticsCustomModulesResponse",
198
+ "SecurityCenterManagementClient",
199
+ "SecurityCenterService",
200
+ "SecurityHealthAnalyticsCustomModule",
201
+ "SimulateSecurityHealthAnalyticsCustomModuleRequest",
202
+ "SimulateSecurityHealthAnalyticsCustomModuleResponse",
203
+ "SimulatedFinding",
204
+ "UpdateEventThreatDetectionCustomModuleRequest",
205
+ "UpdateSecurityCenterServiceRequest",
206
+ "UpdateSecurityHealthAnalyticsCustomModuleRequest",
207
+ "ValidateEventThreatDetectionCustomModuleRequest",
208
+ "ValidateEventThreatDetectionCustomModuleResponse",
209
+ )
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- __version__ = "0.2.0" # {x-release-please-version}
16
+ __version__ = "0.3.0" # {x-release-please-version}
@@ -156,6 +156,34 @@ class SecurityCenterManagementClient(metaclass=SecurityCenterManagementClientMet
156
156
  _DEFAULT_ENDPOINT_TEMPLATE = "securitycentermanagement.{UNIVERSE_DOMAIN}"
157
157
  _DEFAULT_UNIVERSE = "googleapis.com"
158
158
 
159
+ @staticmethod
160
+ def _use_client_cert_effective():
161
+ """Returns whether client certificate should be used for mTLS if the
162
+ google-auth version supports should_use_client_cert automatic mTLS enablement.
163
+
164
+ Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var.
165
+
166
+ Returns:
167
+ bool: whether client certificate should be used for mTLS
168
+ Raises:
169
+ ValueError: (If using a version of google-auth without should_use_client_cert and
170
+ GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.)
171
+ """
172
+ # check if google-auth version supports should_use_client_cert for automatic mTLS enablement
173
+ if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER
174
+ return mtls.should_use_client_cert()
175
+ else: # pragma: NO COVER
176
+ # if unsupported, fallback to reading from env var
177
+ use_client_cert_str = os.getenv(
178
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
179
+ ).lower()
180
+ if use_client_cert_str not in ("true", "false"):
181
+ raise ValueError(
182
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"
183
+ " either `true` or `false`"
184
+ )
185
+ return use_client_cert_str == "true"
186
+
159
187
  @classmethod
160
188
  def from_service_account_info(cls, info: dict, *args, **kwargs):
161
189
  """Creates an instance of this client using the provided credentials
@@ -459,12 +487,8 @@ class SecurityCenterManagementClient(metaclass=SecurityCenterManagementClientMet
459
487
  )
460
488
  if client_options is None:
461
489
  client_options = client_options_lib.ClientOptions()
462
- use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
490
+ use_client_cert = SecurityCenterManagementClient._use_client_cert_effective()
463
491
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
464
- if use_client_cert not in ("true", "false"):
465
- raise ValueError(
466
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
467
- )
468
492
  if use_mtls_endpoint not in ("auto", "never", "always"):
469
493
  raise MutualTLSChannelError(
470
494
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
@@ -472,7 +496,7 @@ class SecurityCenterManagementClient(metaclass=SecurityCenterManagementClientMet
472
496
 
473
497
  # Figure out the client cert source to use.
474
498
  client_cert_source = None
475
- if use_client_cert == "true":
499
+ if use_client_cert:
476
500
  if client_options.client_cert_source:
477
501
  client_cert_source = client_options.client_cert_source
478
502
  elif mtls.has_default_client_cert_source():
@@ -504,20 +528,14 @@ class SecurityCenterManagementClient(metaclass=SecurityCenterManagementClientMet
504
528
  google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
505
529
  is not any of ["auto", "never", "always"].
506
530
  """
507
- use_client_cert = os.getenv(
508
- "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
509
- ).lower()
531
+ use_client_cert = SecurityCenterManagementClient._use_client_cert_effective()
510
532
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
511
533
  universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
512
- if use_client_cert not in ("true", "false"):
513
- raise ValueError(
514
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
515
- )
516
534
  if use_mtls_endpoint not in ("auto", "never", "always"):
517
535
  raise MutualTLSChannelError(
518
536
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
519
537
  )
520
- return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
538
+ return use_client_cert, use_mtls_endpoint, universe_domain_env
521
539
 
522
540
  @staticmethod
523
541
  def _get_client_cert_source(provided_cert_source, use_cert_flag):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-cloud-securitycentermanagement
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Google Cloud Securitycentermanagement API client library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-securitycentermanagement
6
6
  Author: Google LLC
@@ -168,12 +168,19 @@ def test__read_environment_variables():
168
168
  with mock.patch.dict(
169
169
  os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
170
170
  ):
171
- with pytest.raises(ValueError) as excinfo:
172
- SecurityCenterManagementClient._read_environment_variables()
173
- assert (
174
- str(excinfo.value)
175
- == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
176
- )
171
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
172
+ with pytest.raises(ValueError) as excinfo:
173
+ SecurityCenterManagementClient._read_environment_variables()
174
+ assert (
175
+ str(excinfo.value)
176
+ == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
177
+ )
178
+ else:
179
+ assert SecurityCenterManagementClient._read_environment_variables() == (
180
+ False,
181
+ "auto",
182
+ None,
183
+ )
177
184
 
178
185
  with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
179
186
  assert SecurityCenterManagementClient._read_environment_variables() == (
@@ -212,6 +219,107 @@ def test__read_environment_variables():
212
219
  )
213
220
 
214
221
 
222
+ def test_use_client_cert_effective():
223
+ # Test case 1: Test when `should_use_client_cert` returns True.
224
+ # We mock the `should_use_client_cert` function to simulate a scenario where
225
+ # the google-auth library supports automatic mTLS and determines that a
226
+ # client certificate should be used.
227
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
228
+ with mock.patch(
229
+ "google.auth.transport.mtls.should_use_client_cert", return_value=True
230
+ ):
231
+ assert SecurityCenterManagementClient._use_client_cert_effective() is True
232
+
233
+ # Test case 2: Test when `should_use_client_cert` returns False.
234
+ # We mock the `should_use_client_cert` function to simulate a scenario where
235
+ # the google-auth library supports automatic mTLS and determines that a
236
+ # client certificate should NOT be used.
237
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
238
+ with mock.patch(
239
+ "google.auth.transport.mtls.should_use_client_cert", return_value=False
240
+ ):
241
+ assert SecurityCenterManagementClient._use_client_cert_effective() is False
242
+
243
+ # Test case 3: Test when `should_use_client_cert` is unavailable and the
244
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "true".
245
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
246
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
247
+ assert SecurityCenterManagementClient._use_client_cert_effective() is True
248
+
249
+ # Test case 4: Test when `should_use_client_cert` is unavailable and the
250
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "false".
251
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
252
+ with mock.patch.dict(
253
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}
254
+ ):
255
+ assert SecurityCenterManagementClient._use_client_cert_effective() is False
256
+
257
+ # Test case 5: Test when `should_use_client_cert` is unavailable and the
258
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "True".
259
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
260
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "True"}):
261
+ assert SecurityCenterManagementClient._use_client_cert_effective() is True
262
+
263
+ # Test case 6: Test when `should_use_client_cert` is unavailable and the
264
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "False".
265
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
266
+ with mock.patch.dict(
267
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "False"}
268
+ ):
269
+ assert SecurityCenterManagementClient._use_client_cert_effective() is False
270
+
271
+ # Test case 7: Test when `should_use_client_cert` is unavailable and the
272
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "TRUE".
273
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
274
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "TRUE"}):
275
+ assert SecurityCenterManagementClient._use_client_cert_effective() is True
276
+
277
+ # Test case 8: Test when `should_use_client_cert` is unavailable and the
278
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "FALSE".
279
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
280
+ with mock.patch.dict(
281
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "FALSE"}
282
+ ):
283
+ assert SecurityCenterManagementClient._use_client_cert_effective() is False
284
+
285
+ # Test case 9: Test when `should_use_client_cert` is unavailable and the
286
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not set.
287
+ # In this case, the method should return False, which is the default value.
288
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
289
+ with mock.patch.dict(os.environ, clear=True):
290
+ assert SecurityCenterManagementClient._use_client_cert_effective() is False
291
+
292
+ # Test case 10: Test when `should_use_client_cert` is unavailable and the
293
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
294
+ # The method should raise a ValueError as the environment variable must be either
295
+ # "true" or "false".
296
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
297
+ with mock.patch.dict(
298
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}
299
+ ):
300
+ with pytest.raises(ValueError):
301
+ SecurityCenterManagementClient._use_client_cert_effective()
302
+
303
+ # Test case 11: Test when `should_use_client_cert` is available and the
304
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
305
+ # The method should return False as the environment variable is set to an invalid value.
306
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
307
+ with mock.patch.dict(
308
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}
309
+ ):
310
+ assert SecurityCenterManagementClient._use_client_cert_effective() is False
311
+
312
+ # Test case 12: Test when `should_use_client_cert` is available and the
313
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is unset. Also,
314
+ # the GOOGLE_API_CONFIG environment variable is unset.
315
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
316
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": ""}):
317
+ with mock.patch.dict(os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": ""}):
318
+ assert (
319
+ SecurityCenterManagementClient._use_client_cert_effective() is False
320
+ )
321
+
322
+
215
323
  def test__get_client_cert_source():
216
324
  mock_provided_cert_source = mock.Mock()
217
325
  mock_default_cert_source = mock.Mock()
@@ -605,17 +713,6 @@ def test_security_center_management_client_client_options(
605
713
  == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
606
714
  )
607
715
 
608
- # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
609
- with mock.patch.dict(
610
- os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
611
- ):
612
- with pytest.raises(ValueError) as excinfo:
613
- client = client_class(transport=transport_name)
614
- assert (
615
- str(excinfo.value)
616
- == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
617
- )
618
-
619
716
  # Check the case quota_project_id is provided
620
717
  options = client_options.ClientOptions(quota_project_id="octopus")
621
718
  with mock.patch.object(transport_class, "__init__") as patched:
@@ -854,6 +951,119 @@ def test_security_center_management_client_get_mtls_endpoint_and_cert_source(
854
951
  assert api_endpoint == mock_api_endpoint
855
952
  assert cert_source is None
856
953
 
954
+ # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "Unsupported".
955
+ with mock.patch.dict(
956
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
957
+ ):
958
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
959
+ mock_client_cert_source = mock.Mock()
960
+ mock_api_endpoint = "foo"
961
+ options = client_options.ClientOptions(
962
+ client_cert_source=mock_client_cert_source,
963
+ api_endpoint=mock_api_endpoint,
964
+ )
965
+ api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(
966
+ options
967
+ )
968
+ assert api_endpoint == mock_api_endpoint
969
+ assert cert_source is None
970
+
971
+ # Test cases for mTLS enablement when GOOGLE_API_USE_CLIENT_CERTIFICATE is unset.
972
+ test_cases = [
973
+ (
974
+ # With workloads present in config, mTLS is enabled.
975
+ {
976
+ "version": 1,
977
+ "cert_configs": {
978
+ "workload": {
979
+ "cert_path": "path/to/cert/file",
980
+ "key_path": "path/to/key/file",
981
+ }
982
+ },
983
+ },
984
+ mock_client_cert_source,
985
+ ),
986
+ (
987
+ # With workloads not present in config, mTLS is disabled.
988
+ {
989
+ "version": 1,
990
+ "cert_configs": {},
991
+ },
992
+ None,
993
+ ),
994
+ ]
995
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
996
+ for config_data, expected_cert_source in test_cases:
997
+ env = os.environ.copy()
998
+ env.pop("GOOGLE_API_USE_CLIENT_CERTIFICATE", None)
999
+ with mock.patch.dict(os.environ, env, clear=True):
1000
+ config_filename = "mock_certificate_config.json"
1001
+ config_file_content = json.dumps(config_data)
1002
+ m = mock.mock_open(read_data=config_file_content)
1003
+ with mock.patch("builtins.open", m):
1004
+ with mock.patch.dict(
1005
+ os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": config_filename}
1006
+ ):
1007
+ mock_api_endpoint = "foo"
1008
+ options = client_options.ClientOptions(
1009
+ client_cert_source=mock_client_cert_source,
1010
+ api_endpoint=mock_api_endpoint,
1011
+ )
1012
+ (
1013
+ api_endpoint,
1014
+ cert_source,
1015
+ ) = client_class.get_mtls_endpoint_and_cert_source(options)
1016
+ assert api_endpoint == mock_api_endpoint
1017
+ assert cert_source is expected_cert_source
1018
+
1019
+ # Test cases for mTLS enablement when GOOGLE_API_USE_CLIENT_CERTIFICATE is unset(empty).
1020
+ test_cases = [
1021
+ (
1022
+ # With workloads present in config, mTLS is enabled.
1023
+ {
1024
+ "version": 1,
1025
+ "cert_configs": {
1026
+ "workload": {
1027
+ "cert_path": "path/to/cert/file",
1028
+ "key_path": "path/to/key/file",
1029
+ }
1030
+ },
1031
+ },
1032
+ mock_client_cert_source,
1033
+ ),
1034
+ (
1035
+ # With workloads not present in config, mTLS is disabled.
1036
+ {
1037
+ "version": 1,
1038
+ "cert_configs": {},
1039
+ },
1040
+ None,
1041
+ ),
1042
+ ]
1043
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
1044
+ for config_data, expected_cert_source in test_cases:
1045
+ env = os.environ.copy()
1046
+ env.pop("GOOGLE_API_USE_CLIENT_CERTIFICATE", "")
1047
+ with mock.patch.dict(os.environ, env, clear=True):
1048
+ config_filename = "mock_certificate_config.json"
1049
+ config_file_content = json.dumps(config_data)
1050
+ m = mock.mock_open(read_data=config_file_content)
1051
+ with mock.patch("builtins.open", m):
1052
+ with mock.patch.dict(
1053
+ os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": config_filename}
1054
+ ):
1055
+ mock_api_endpoint = "foo"
1056
+ options = client_options.ClientOptions(
1057
+ client_cert_source=mock_client_cert_source,
1058
+ api_endpoint=mock_api_endpoint,
1059
+ )
1060
+ (
1061
+ api_endpoint,
1062
+ cert_source,
1063
+ ) = client_class.get_mtls_endpoint_and_cert_source(options)
1064
+ assert api_endpoint == mock_api_endpoint
1065
+ assert cert_source is expected_cert_source
1066
+
857
1067
  # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never".
858
1068
  with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
859
1069
  api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source()
@@ -904,18 +1114,6 @@ def test_security_center_management_client_get_mtls_endpoint_and_cert_source(
904
1114
  == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
905
1115
  )
906
1116
 
907
- # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
908
- with mock.patch.dict(
909
- os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
910
- ):
911
- with pytest.raises(ValueError) as excinfo:
912
- client_class.get_mtls_endpoint_and_cert_source()
913
-
914
- assert (
915
- str(excinfo.value)
916
- == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
917
- )
918
-
919
1117
 
920
1118
  @pytest.mark.parametrize(
921
1119
  "client_class",
@@ -21661,6 +21859,7 @@ def test_security_center_management_grpc_asyncio_transport_channel():
21661
21859
 
21662
21860
  # Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are
21663
21861
  # removed from grpc/grpc_asyncio transport constructor.
21862
+ @pytest.mark.filterwarnings("ignore::FutureWarning")
21664
21863
  @pytest.mark.parametrize(
21665
21864
  "transport_class",
21666
21865
  [
@@ -1,105 +0,0 @@
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
- from google.cloud.securitycentermanagement_v1 import gapic_version as package_version
17
-
18
- __version__ = package_version.__version__
19
-
20
-
21
- from .services.security_center_management import (
22
- SecurityCenterManagementAsyncClient,
23
- SecurityCenterManagementClient,
24
- )
25
- from .types.security_center_management import (
26
- CreateEventThreatDetectionCustomModuleRequest,
27
- CreateSecurityHealthAnalyticsCustomModuleRequest,
28
- CustomConfig,
29
- DeleteEventThreatDetectionCustomModuleRequest,
30
- DeleteSecurityHealthAnalyticsCustomModuleRequest,
31
- EffectiveEventThreatDetectionCustomModule,
32
- EffectiveSecurityHealthAnalyticsCustomModule,
33
- EventThreatDetectionCustomModule,
34
- GetEffectiveEventThreatDetectionCustomModuleRequest,
35
- GetEffectiveSecurityHealthAnalyticsCustomModuleRequest,
36
- GetEventThreatDetectionCustomModuleRequest,
37
- GetSecurityCenterServiceRequest,
38
- GetSecurityHealthAnalyticsCustomModuleRequest,
39
- ListDescendantEventThreatDetectionCustomModulesRequest,
40
- ListDescendantEventThreatDetectionCustomModulesResponse,
41
- ListDescendantSecurityHealthAnalyticsCustomModulesRequest,
42
- ListDescendantSecurityHealthAnalyticsCustomModulesResponse,
43
- ListEffectiveEventThreatDetectionCustomModulesRequest,
44
- ListEffectiveEventThreatDetectionCustomModulesResponse,
45
- ListEffectiveSecurityHealthAnalyticsCustomModulesRequest,
46
- ListEffectiveSecurityHealthAnalyticsCustomModulesResponse,
47
- ListEventThreatDetectionCustomModulesRequest,
48
- ListEventThreatDetectionCustomModulesResponse,
49
- ListSecurityCenterServicesRequest,
50
- ListSecurityCenterServicesResponse,
51
- ListSecurityHealthAnalyticsCustomModulesRequest,
52
- ListSecurityHealthAnalyticsCustomModulesResponse,
53
- SecurityCenterService,
54
- SecurityHealthAnalyticsCustomModule,
55
- SimulatedFinding,
56
- SimulateSecurityHealthAnalyticsCustomModuleRequest,
57
- SimulateSecurityHealthAnalyticsCustomModuleResponse,
58
- UpdateEventThreatDetectionCustomModuleRequest,
59
- UpdateSecurityCenterServiceRequest,
60
- UpdateSecurityHealthAnalyticsCustomModuleRequest,
61
- ValidateEventThreatDetectionCustomModuleRequest,
62
- ValidateEventThreatDetectionCustomModuleResponse,
63
- )
64
-
65
- __all__ = (
66
- "SecurityCenterManagementAsyncClient",
67
- "CreateEventThreatDetectionCustomModuleRequest",
68
- "CreateSecurityHealthAnalyticsCustomModuleRequest",
69
- "CustomConfig",
70
- "DeleteEventThreatDetectionCustomModuleRequest",
71
- "DeleteSecurityHealthAnalyticsCustomModuleRequest",
72
- "EffectiveEventThreatDetectionCustomModule",
73
- "EffectiveSecurityHealthAnalyticsCustomModule",
74
- "EventThreatDetectionCustomModule",
75
- "GetEffectiveEventThreatDetectionCustomModuleRequest",
76
- "GetEffectiveSecurityHealthAnalyticsCustomModuleRequest",
77
- "GetEventThreatDetectionCustomModuleRequest",
78
- "GetSecurityCenterServiceRequest",
79
- "GetSecurityHealthAnalyticsCustomModuleRequest",
80
- "ListDescendantEventThreatDetectionCustomModulesRequest",
81
- "ListDescendantEventThreatDetectionCustomModulesResponse",
82
- "ListDescendantSecurityHealthAnalyticsCustomModulesRequest",
83
- "ListDescendantSecurityHealthAnalyticsCustomModulesResponse",
84
- "ListEffectiveEventThreatDetectionCustomModulesRequest",
85
- "ListEffectiveEventThreatDetectionCustomModulesResponse",
86
- "ListEffectiveSecurityHealthAnalyticsCustomModulesRequest",
87
- "ListEffectiveSecurityHealthAnalyticsCustomModulesResponse",
88
- "ListEventThreatDetectionCustomModulesRequest",
89
- "ListEventThreatDetectionCustomModulesResponse",
90
- "ListSecurityCenterServicesRequest",
91
- "ListSecurityCenterServicesResponse",
92
- "ListSecurityHealthAnalyticsCustomModulesRequest",
93
- "ListSecurityHealthAnalyticsCustomModulesResponse",
94
- "SecurityCenterManagementClient",
95
- "SecurityCenterService",
96
- "SecurityHealthAnalyticsCustomModule",
97
- "SimulateSecurityHealthAnalyticsCustomModuleRequest",
98
- "SimulateSecurityHealthAnalyticsCustomModuleResponse",
99
- "SimulatedFinding",
100
- "UpdateEventThreatDetectionCustomModuleRequest",
101
- "UpdateSecurityCenterServiceRequest",
102
- "UpdateSecurityHealthAnalyticsCustomModuleRequest",
103
- "ValidateEventThreatDetectionCustomModuleRequest",
104
- "ValidateEventThreatDetectionCustomModuleResponse",
105
- )