google-cloud-modelarmor 0.3.0__tar.gz → 0.4.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 (58) hide show
  1. {google_cloud_modelarmor-0.3.0/google_cloud_modelarmor.egg-info → google_cloud_modelarmor-0.4.0}/PKG-INFO +1 -1
  2. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor/gapic_version.py +1 -1
  3. google_cloud_modelarmor-0.4.0/google/cloud/modelarmor_v1/__init__.py +222 -0
  4. {google_cloud_modelarmor-0.3.0/google/cloud/modelarmor_v1beta → google_cloud_modelarmor-0.4.0/google/cloud/modelarmor_v1}/gapic_version.py +1 -1
  5. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/model_armor/client.py +32 -14
  6. google_cloud_modelarmor-0.4.0/google/cloud/modelarmor_v1beta/__init__.py +222 -0
  7. {google_cloud_modelarmor-0.3.0/google/cloud/modelarmor_v1 → google_cloud_modelarmor-0.4.0/google/cloud/modelarmor_v1beta}/gapic_version.py +1 -1
  8. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/model_armor/client.py +32 -14
  9. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0/google_cloud_modelarmor.egg-info}/PKG-INFO +1 -1
  10. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/tests/unit/gapic/modelarmor_v1/test_model_armor.py +226 -29
  11. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/tests/unit/gapic/modelarmor_v1beta/test_model_armor.py +226 -29
  12. google_cloud_modelarmor-0.3.0/google/cloud/modelarmor_v1/__init__.py +0 -118
  13. google_cloud_modelarmor-0.3.0/google/cloud/modelarmor_v1beta/__init__.py +0 -118
  14. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/LICENSE +0 -0
  15. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/MANIFEST.in +0 -0
  16. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/README.rst +0 -0
  17. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor/__init__.py +0 -0
  18. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor/py.typed +0 -0
  19. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/gapic_metadata.json +0 -0
  20. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/py.typed +0 -0
  21. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/__init__.py +0 -0
  22. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/model_armor/__init__.py +0 -0
  23. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/model_armor/async_client.py +0 -0
  24. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/model_armor/pagers.py +0 -0
  25. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/model_armor/transports/__init__.py +0 -0
  26. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/model_armor/transports/base.py +0 -0
  27. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/model_armor/transports/grpc.py +0 -0
  28. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/model_armor/transports/grpc_asyncio.py +0 -0
  29. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/model_armor/transports/rest.py +0 -0
  30. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/services/model_armor/transports/rest_base.py +0 -0
  31. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/types/__init__.py +0 -0
  32. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1/types/service.py +0 -0
  33. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/gapic_metadata.json +0 -0
  34. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/py.typed +0 -0
  35. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/__init__.py +0 -0
  36. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/model_armor/__init__.py +0 -0
  37. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/model_armor/async_client.py +0 -0
  38. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/model_armor/pagers.py +0 -0
  39. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/model_armor/transports/__init__.py +0 -0
  40. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/model_armor/transports/base.py +0 -0
  41. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/model_armor/transports/grpc.py +0 -0
  42. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/model_armor/transports/grpc_asyncio.py +0 -0
  43. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/model_armor/transports/rest.py +0 -0
  44. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/services/model_armor/transports/rest_base.py +0 -0
  45. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/types/__init__.py +0 -0
  46. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google/cloud/modelarmor_v1beta/types/service.py +0 -0
  47. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google_cloud_modelarmor.egg-info/SOURCES.txt +0 -0
  48. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google_cloud_modelarmor.egg-info/dependency_links.txt +0 -0
  49. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google_cloud_modelarmor.egg-info/not-zip-safe +0 -0
  50. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google_cloud_modelarmor.egg-info/requires.txt +0 -0
  51. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/google_cloud_modelarmor.egg-info/top_level.txt +0 -0
  52. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/setup.cfg +0 -0
  53. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/setup.py +0 -0
  54. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/tests/__init__.py +0 -0
  55. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/tests/unit/__init__.py +0 -0
  56. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/tests/unit/gapic/__init__.py +0 -0
  57. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/tests/unit/gapic/modelarmor_v1/__init__.py +0 -0
  58. {google_cloud_modelarmor-0.3.0 → google_cloud_modelarmor-0.4.0}/tests/unit/gapic/modelarmor_v1beta/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-cloud-modelarmor
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Google Cloud Modelarmor API client library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-modelarmor
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.3.0" # {x-release-please-version}
16
+ __version__ = "0.4.0" # {x-release-please-version}
@@ -0,0 +1,222 @@
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.modelarmor_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.model_armor import ModelArmorAsyncClient, ModelArmorClient
32
+ from .types.service import (
33
+ AiPlatformFloorSetting,
34
+ ByteDataItem,
35
+ CreateTemplateRequest,
36
+ CsamFilterResult,
37
+ DataItem,
38
+ DeleteTemplateRequest,
39
+ DetectionConfidenceLevel,
40
+ FilterConfig,
41
+ FilterExecutionState,
42
+ FilterMatchState,
43
+ FilterResult,
44
+ FloorSetting,
45
+ GetFloorSettingRequest,
46
+ GetTemplateRequest,
47
+ InvocationResult,
48
+ ListTemplatesRequest,
49
+ ListTemplatesResponse,
50
+ MaliciousUriFilterResult,
51
+ MaliciousUriFilterSettings,
52
+ MessageItem,
53
+ MultiLanguageDetectionMetadata,
54
+ PiAndJailbreakFilterResult,
55
+ PiAndJailbreakFilterSettings,
56
+ RaiFilterResult,
57
+ RaiFilterSettings,
58
+ RaiFilterType,
59
+ RangeInfo,
60
+ SanitizationResult,
61
+ SanitizeModelResponseRequest,
62
+ SanitizeModelResponseResponse,
63
+ SanitizeUserPromptRequest,
64
+ SanitizeUserPromptResponse,
65
+ SdpAdvancedConfig,
66
+ SdpBasicConfig,
67
+ SdpDeidentifyResult,
68
+ SdpFilterResult,
69
+ SdpFilterSettings,
70
+ SdpFinding,
71
+ SdpFindingLikelihood,
72
+ SdpInspectResult,
73
+ Template,
74
+ UpdateFloorSettingRequest,
75
+ UpdateTemplateRequest,
76
+ VirusDetail,
77
+ VirusScanFilterResult,
78
+ )
79
+
80
+ if hasattr(api_core, "check_python_version") and hasattr(
81
+ api_core, "check_dependency_versions"
82
+ ): # pragma: NO COVER
83
+ api_core.check_python_version("google.cloud.modelarmor_v1") # type: ignore
84
+ api_core.check_dependency_versions("google.cloud.modelarmor_v1") # type: ignore
85
+ else: # pragma: NO COVER
86
+ # An older version of api_core is installed which does not define the
87
+ # functions above. We do equivalent checks manually.
88
+ try:
89
+ import sys
90
+ import warnings
91
+
92
+ _py_version_str = sys.version.split()[0]
93
+ _package_label = "google.cloud.modelarmor_v1"
94
+ if sys.version_info < (3, 9):
95
+ warnings.warn(
96
+ "You are using a non-supported Python version "
97
+ + f"({_py_version_str}). Google will not post any further "
98
+ + f"updates to {_package_label} supporting this Python version. "
99
+ + "Please upgrade to the latest Python version, or at "
100
+ + f"least to Python 3.9, and then update {_package_label}.",
101
+ FutureWarning,
102
+ )
103
+ if sys.version_info[:2] == (3, 9):
104
+ warnings.warn(
105
+ f"You are using a Python version ({_py_version_str}) "
106
+ + f"which Google will stop supporting in {_package_label} in "
107
+ + "January 2026. Please "
108
+ + "upgrade to the latest Python version, or at "
109
+ + "least to Python 3.10, before then, and "
110
+ + f"then update {_package_label}.",
111
+ FutureWarning,
112
+ )
113
+
114
+ def parse_version_to_tuple(version_string: str):
115
+ """Safely converts a semantic version string to a comparable tuple of integers.
116
+ Example: "4.25.8" -> (4, 25, 8)
117
+ Ignores non-numeric parts and handles common version formats.
118
+ Args:
119
+ version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
120
+ Returns:
121
+ Tuple of integers for the parsed version string.
122
+ """
123
+ parts = []
124
+ for part in version_string.split("."):
125
+ try:
126
+ parts.append(int(part))
127
+ except ValueError:
128
+ # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
129
+ # This is a simplification compared to 'packaging.parse_version', but sufficient
130
+ # for comparing strictly numeric semantic versions.
131
+ break
132
+ return tuple(parts)
133
+
134
+ def _get_version(dependency_name):
135
+ try:
136
+ version_string: str = metadata.version(dependency_name)
137
+ parsed_version = parse_version_to_tuple(version_string)
138
+ return (parsed_version, version_string)
139
+ except Exception:
140
+ # Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
141
+ # or errors during parse_version_to_tuple
142
+ return (None, "--")
143
+
144
+ _dependency_package = "google.protobuf"
145
+ _next_supported_version = "4.25.8"
146
+ _next_supported_version_tuple = (4, 25, 8)
147
+ _recommendation = " (we recommend 6.x)"
148
+ (_version_used, _version_used_string) = _get_version(_dependency_package)
149
+ if _version_used and _version_used < _next_supported_version_tuple:
150
+ warnings.warn(
151
+ f"Package {_package_label} depends on "
152
+ + f"{_dependency_package}, currently installed at version "
153
+ + f"{_version_used_string}. Future updates to "
154
+ + f"{_package_label} will require {_dependency_package} at "
155
+ + f"version {_next_supported_version} or higher{_recommendation}."
156
+ + " Please ensure "
157
+ + "that either (a) your Python environment doesn't pin the "
158
+ + f"version of {_dependency_package}, so that updates to "
159
+ + f"{_package_label} can require the higher version, or "
160
+ + "(b) you manually update your Python environment to use at "
161
+ + f"least version {_next_supported_version} of "
162
+ + f"{_dependency_package}.",
163
+ FutureWarning,
164
+ )
165
+ except Exception:
166
+ warnings.warn(
167
+ "Could not determine the version of Python "
168
+ + "currently being used. To continue receiving "
169
+ + "updates for {_package_label}, ensure you are "
170
+ + "using a supported version of Python; see "
171
+ + "https://devguide.python.org/versions/"
172
+ )
173
+
174
+ __all__ = (
175
+ "ModelArmorAsyncClient",
176
+ "AiPlatformFloorSetting",
177
+ "ByteDataItem",
178
+ "CreateTemplateRequest",
179
+ "CsamFilterResult",
180
+ "DataItem",
181
+ "DeleteTemplateRequest",
182
+ "DetectionConfidenceLevel",
183
+ "FilterConfig",
184
+ "FilterExecutionState",
185
+ "FilterMatchState",
186
+ "FilterResult",
187
+ "FloorSetting",
188
+ "GetFloorSettingRequest",
189
+ "GetTemplateRequest",
190
+ "InvocationResult",
191
+ "ListTemplatesRequest",
192
+ "ListTemplatesResponse",
193
+ "MaliciousUriFilterResult",
194
+ "MaliciousUriFilterSettings",
195
+ "MessageItem",
196
+ "ModelArmorClient",
197
+ "MultiLanguageDetectionMetadata",
198
+ "PiAndJailbreakFilterResult",
199
+ "PiAndJailbreakFilterSettings",
200
+ "RaiFilterResult",
201
+ "RaiFilterSettings",
202
+ "RaiFilterType",
203
+ "RangeInfo",
204
+ "SanitizationResult",
205
+ "SanitizeModelResponseRequest",
206
+ "SanitizeModelResponseResponse",
207
+ "SanitizeUserPromptRequest",
208
+ "SanitizeUserPromptResponse",
209
+ "SdpAdvancedConfig",
210
+ "SdpBasicConfig",
211
+ "SdpDeidentifyResult",
212
+ "SdpFilterResult",
213
+ "SdpFilterSettings",
214
+ "SdpFinding",
215
+ "SdpFindingLikelihood",
216
+ "SdpInspectResult",
217
+ "Template",
218
+ "UpdateFloorSettingRequest",
219
+ "UpdateTemplateRequest",
220
+ "VirusDetail",
221
+ "VirusScanFilterResult",
222
+ )
@@ -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.3.0" # {x-release-please-version}
16
+ __version__ = "0.4.0" # {x-release-please-version}
@@ -151,6 +151,34 @@ class ModelArmorClient(metaclass=ModelArmorClientMeta):
151
151
  _DEFAULT_ENDPOINT_TEMPLATE = "modelarmor.{UNIVERSE_DOMAIN}"
152
152
  _DEFAULT_UNIVERSE = "googleapis.com"
153
153
 
154
+ @staticmethod
155
+ def _use_client_cert_effective():
156
+ """Returns whether client certificate should be used for mTLS if the
157
+ google-auth version supports should_use_client_cert automatic mTLS enablement.
158
+
159
+ Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var.
160
+
161
+ Returns:
162
+ bool: whether client certificate should be used for mTLS
163
+ Raises:
164
+ ValueError: (If using a version of google-auth without should_use_client_cert and
165
+ GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.)
166
+ """
167
+ # check if google-auth version supports should_use_client_cert for automatic mTLS enablement
168
+ if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER
169
+ return mtls.should_use_client_cert()
170
+ else: # pragma: NO COVER
171
+ # if unsupported, fallback to reading from env var
172
+ use_client_cert_str = os.getenv(
173
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
174
+ ).lower()
175
+ if use_client_cert_str not in ("true", "false"):
176
+ raise ValueError(
177
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"
178
+ " either `true` or `false`"
179
+ )
180
+ return use_client_cert_str == "true"
181
+
154
182
  @classmethod
155
183
  def from_service_account_info(cls, info: dict, *args, **kwargs):
156
184
  """Creates an instance of this client using the provided credentials
@@ -358,12 +386,8 @@ class ModelArmorClient(metaclass=ModelArmorClientMeta):
358
386
  )
359
387
  if client_options is None:
360
388
  client_options = client_options_lib.ClientOptions()
361
- use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
389
+ use_client_cert = ModelArmorClient._use_client_cert_effective()
362
390
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
363
- if use_client_cert not in ("true", "false"):
364
- raise ValueError(
365
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
366
- )
367
391
  if use_mtls_endpoint not in ("auto", "never", "always"):
368
392
  raise MutualTLSChannelError(
369
393
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
@@ -371,7 +395,7 @@ class ModelArmorClient(metaclass=ModelArmorClientMeta):
371
395
 
372
396
  # Figure out the client cert source to use.
373
397
  client_cert_source = None
374
- if use_client_cert == "true":
398
+ if use_client_cert:
375
399
  if client_options.client_cert_source:
376
400
  client_cert_source = client_options.client_cert_source
377
401
  elif mtls.has_default_client_cert_source():
@@ -403,20 +427,14 @@ class ModelArmorClient(metaclass=ModelArmorClientMeta):
403
427
  google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
404
428
  is not any of ["auto", "never", "always"].
405
429
  """
406
- use_client_cert = os.getenv(
407
- "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
408
- ).lower()
430
+ use_client_cert = ModelArmorClient._use_client_cert_effective()
409
431
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
410
432
  universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
411
- if use_client_cert not in ("true", "false"):
412
- raise ValueError(
413
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
414
- )
415
433
  if use_mtls_endpoint not in ("auto", "never", "always"):
416
434
  raise MutualTLSChannelError(
417
435
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
418
436
  )
419
- return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
437
+ return use_client_cert, use_mtls_endpoint, universe_domain_env
420
438
 
421
439
  @staticmethod
422
440
  def _get_client_cert_source(provided_cert_source, use_cert_flag):
@@ -0,0 +1,222 @@
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.modelarmor_v1beta 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.model_armor import ModelArmorAsyncClient, ModelArmorClient
32
+ from .types.service import (
33
+ AiPlatformFloorSetting,
34
+ ByteDataItem,
35
+ CreateTemplateRequest,
36
+ CsamFilterResult,
37
+ DataItem,
38
+ DeleteTemplateRequest,
39
+ DetectionConfidenceLevel,
40
+ FilterConfig,
41
+ FilterExecutionState,
42
+ FilterMatchState,
43
+ FilterResult,
44
+ FloorSetting,
45
+ GetFloorSettingRequest,
46
+ GetTemplateRequest,
47
+ InvocationResult,
48
+ ListTemplatesRequest,
49
+ ListTemplatesResponse,
50
+ MaliciousUriFilterResult,
51
+ MaliciousUriFilterSettings,
52
+ MessageItem,
53
+ MultiLanguageDetectionMetadata,
54
+ PiAndJailbreakFilterResult,
55
+ PiAndJailbreakFilterSettings,
56
+ RaiFilterResult,
57
+ RaiFilterSettings,
58
+ RaiFilterType,
59
+ RangeInfo,
60
+ SanitizationResult,
61
+ SanitizeModelResponseRequest,
62
+ SanitizeModelResponseResponse,
63
+ SanitizeUserPromptRequest,
64
+ SanitizeUserPromptResponse,
65
+ SdpAdvancedConfig,
66
+ SdpBasicConfig,
67
+ SdpDeidentifyResult,
68
+ SdpFilterResult,
69
+ SdpFilterSettings,
70
+ SdpFinding,
71
+ SdpFindingLikelihood,
72
+ SdpInspectResult,
73
+ Template,
74
+ UpdateFloorSettingRequest,
75
+ UpdateTemplateRequest,
76
+ VirusDetail,
77
+ VirusScanFilterResult,
78
+ )
79
+
80
+ if hasattr(api_core, "check_python_version") and hasattr(
81
+ api_core, "check_dependency_versions"
82
+ ): # pragma: NO COVER
83
+ api_core.check_python_version("google.cloud.modelarmor_v1beta") # type: ignore
84
+ api_core.check_dependency_versions("google.cloud.modelarmor_v1beta") # type: ignore
85
+ else: # pragma: NO COVER
86
+ # An older version of api_core is installed which does not define the
87
+ # functions above. We do equivalent checks manually.
88
+ try:
89
+ import sys
90
+ import warnings
91
+
92
+ _py_version_str = sys.version.split()[0]
93
+ _package_label = "google.cloud.modelarmor_v1beta"
94
+ if sys.version_info < (3, 9):
95
+ warnings.warn(
96
+ "You are using a non-supported Python version "
97
+ + f"({_py_version_str}). Google will not post any further "
98
+ + f"updates to {_package_label} supporting this Python version. "
99
+ + "Please upgrade to the latest Python version, or at "
100
+ + f"least to Python 3.9, and then update {_package_label}.",
101
+ FutureWarning,
102
+ )
103
+ if sys.version_info[:2] == (3, 9):
104
+ warnings.warn(
105
+ f"You are using a Python version ({_py_version_str}) "
106
+ + f"which Google will stop supporting in {_package_label} in "
107
+ + "January 2026. Please "
108
+ + "upgrade to the latest Python version, or at "
109
+ + "least to Python 3.10, before then, and "
110
+ + f"then update {_package_label}.",
111
+ FutureWarning,
112
+ )
113
+
114
+ def parse_version_to_tuple(version_string: str):
115
+ """Safely converts a semantic version string to a comparable tuple of integers.
116
+ Example: "4.25.8" -> (4, 25, 8)
117
+ Ignores non-numeric parts and handles common version formats.
118
+ Args:
119
+ version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
120
+ Returns:
121
+ Tuple of integers for the parsed version string.
122
+ """
123
+ parts = []
124
+ for part in version_string.split("."):
125
+ try:
126
+ parts.append(int(part))
127
+ except ValueError:
128
+ # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
129
+ # This is a simplification compared to 'packaging.parse_version', but sufficient
130
+ # for comparing strictly numeric semantic versions.
131
+ break
132
+ return tuple(parts)
133
+
134
+ def _get_version(dependency_name):
135
+ try:
136
+ version_string: str = metadata.version(dependency_name)
137
+ parsed_version = parse_version_to_tuple(version_string)
138
+ return (parsed_version, version_string)
139
+ except Exception:
140
+ # Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
141
+ # or errors during parse_version_to_tuple
142
+ return (None, "--")
143
+
144
+ _dependency_package = "google.protobuf"
145
+ _next_supported_version = "4.25.8"
146
+ _next_supported_version_tuple = (4, 25, 8)
147
+ _recommendation = " (we recommend 6.x)"
148
+ (_version_used, _version_used_string) = _get_version(_dependency_package)
149
+ if _version_used and _version_used < _next_supported_version_tuple:
150
+ warnings.warn(
151
+ f"Package {_package_label} depends on "
152
+ + f"{_dependency_package}, currently installed at version "
153
+ + f"{_version_used_string}. Future updates to "
154
+ + f"{_package_label} will require {_dependency_package} at "
155
+ + f"version {_next_supported_version} or higher{_recommendation}."
156
+ + " Please ensure "
157
+ + "that either (a) your Python environment doesn't pin the "
158
+ + f"version of {_dependency_package}, so that updates to "
159
+ + f"{_package_label} can require the higher version, or "
160
+ + "(b) you manually update your Python environment to use at "
161
+ + f"least version {_next_supported_version} of "
162
+ + f"{_dependency_package}.",
163
+ FutureWarning,
164
+ )
165
+ except Exception:
166
+ warnings.warn(
167
+ "Could not determine the version of Python "
168
+ + "currently being used. To continue receiving "
169
+ + "updates for {_package_label}, ensure you are "
170
+ + "using a supported version of Python; see "
171
+ + "https://devguide.python.org/versions/"
172
+ )
173
+
174
+ __all__ = (
175
+ "ModelArmorAsyncClient",
176
+ "AiPlatformFloorSetting",
177
+ "ByteDataItem",
178
+ "CreateTemplateRequest",
179
+ "CsamFilterResult",
180
+ "DataItem",
181
+ "DeleteTemplateRequest",
182
+ "DetectionConfidenceLevel",
183
+ "FilterConfig",
184
+ "FilterExecutionState",
185
+ "FilterMatchState",
186
+ "FilterResult",
187
+ "FloorSetting",
188
+ "GetFloorSettingRequest",
189
+ "GetTemplateRequest",
190
+ "InvocationResult",
191
+ "ListTemplatesRequest",
192
+ "ListTemplatesResponse",
193
+ "MaliciousUriFilterResult",
194
+ "MaliciousUriFilterSettings",
195
+ "MessageItem",
196
+ "ModelArmorClient",
197
+ "MultiLanguageDetectionMetadata",
198
+ "PiAndJailbreakFilterResult",
199
+ "PiAndJailbreakFilterSettings",
200
+ "RaiFilterResult",
201
+ "RaiFilterSettings",
202
+ "RaiFilterType",
203
+ "RangeInfo",
204
+ "SanitizationResult",
205
+ "SanitizeModelResponseRequest",
206
+ "SanitizeModelResponseResponse",
207
+ "SanitizeUserPromptRequest",
208
+ "SanitizeUserPromptResponse",
209
+ "SdpAdvancedConfig",
210
+ "SdpBasicConfig",
211
+ "SdpDeidentifyResult",
212
+ "SdpFilterResult",
213
+ "SdpFilterSettings",
214
+ "SdpFinding",
215
+ "SdpFindingLikelihood",
216
+ "SdpInspectResult",
217
+ "Template",
218
+ "UpdateFloorSettingRequest",
219
+ "UpdateTemplateRequest",
220
+ "VirusDetail",
221
+ "VirusScanFilterResult",
222
+ )
@@ -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.3.0" # {x-release-please-version}
16
+ __version__ = "0.4.0" # {x-release-please-version}
@@ -151,6 +151,34 @@ class ModelArmorClient(metaclass=ModelArmorClientMeta):
151
151
  _DEFAULT_ENDPOINT_TEMPLATE = "modelarmor.{UNIVERSE_DOMAIN}"
152
152
  _DEFAULT_UNIVERSE = "googleapis.com"
153
153
 
154
+ @staticmethod
155
+ def _use_client_cert_effective():
156
+ """Returns whether client certificate should be used for mTLS if the
157
+ google-auth version supports should_use_client_cert automatic mTLS enablement.
158
+
159
+ Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var.
160
+
161
+ Returns:
162
+ bool: whether client certificate should be used for mTLS
163
+ Raises:
164
+ ValueError: (If using a version of google-auth without should_use_client_cert and
165
+ GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.)
166
+ """
167
+ # check if google-auth version supports should_use_client_cert for automatic mTLS enablement
168
+ if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER
169
+ return mtls.should_use_client_cert()
170
+ else: # pragma: NO COVER
171
+ # if unsupported, fallback to reading from env var
172
+ use_client_cert_str = os.getenv(
173
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
174
+ ).lower()
175
+ if use_client_cert_str not in ("true", "false"):
176
+ raise ValueError(
177
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"
178
+ " either `true` or `false`"
179
+ )
180
+ return use_client_cert_str == "true"
181
+
154
182
  @classmethod
155
183
  def from_service_account_info(cls, info: dict, *args, **kwargs):
156
184
  """Creates an instance of this client using the provided credentials
@@ -358,12 +386,8 @@ class ModelArmorClient(metaclass=ModelArmorClientMeta):
358
386
  )
359
387
  if client_options is None:
360
388
  client_options = client_options_lib.ClientOptions()
361
- use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
389
+ use_client_cert = ModelArmorClient._use_client_cert_effective()
362
390
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
363
- if use_client_cert not in ("true", "false"):
364
- raise ValueError(
365
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
366
- )
367
391
  if use_mtls_endpoint not in ("auto", "never", "always"):
368
392
  raise MutualTLSChannelError(
369
393
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
@@ -371,7 +395,7 @@ class ModelArmorClient(metaclass=ModelArmorClientMeta):
371
395
 
372
396
  # Figure out the client cert source to use.
373
397
  client_cert_source = None
374
- if use_client_cert == "true":
398
+ if use_client_cert:
375
399
  if client_options.client_cert_source:
376
400
  client_cert_source = client_options.client_cert_source
377
401
  elif mtls.has_default_client_cert_source():
@@ -403,20 +427,14 @@ class ModelArmorClient(metaclass=ModelArmorClientMeta):
403
427
  google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
404
428
  is not any of ["auto", "never", "always"].
405
429
  """
406
- use_client_cert = os.getenv(
407
- "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
408
- ).lower()
430
+ use_client_cert = ModelArmorClient._use_client_cert_effective()
409
431
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
410
432
  universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
411
- if use_client_cert not in ("true", "false"):
412
- raise ValueError(
413
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
414
- )
415
433
  if use_mtls_endpoint not in ("auto", "never", "always"):
416
434
  raise MutualTLSChannelError(
417
435
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
418
436
  )
419
- return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
437
+ return use_client_cert, use_mtls_endpoint, universe_domain_env
420
438
 
421
439
  @staticmethod
422
440
  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-modelarmor
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Google Cloud Modelarmor API client library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-modelarmor
6
6
  Author: Google LLC