google-cloud-dataform 0.7.0__tar.gz → 0.8.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 (56) hide show
  1. {google_cloud_dataform-0.7.0/google_cloud_dataform.egg-info → google_cloud_dataform-0.8.0}/PKG-INFO +1 -1
  2. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform/gapic_version.py +1 -1
  3. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/__init__.py +104 -0
  4. {google_cloud_dataform-0.7.0/google/cloud/dataform_v1beta1 → google_cloud_dataform-0.8.0/google/cloud/dataform_v1}/gapic_version.py +1 -1
  5. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/dataform/client.py +32 -14
  6. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/__init__.py +104 -0
  7. {google_cloud_dataform-0.7.0/google/cloud/dataform_v1 → google_cloud_dataform-0.8.0/google/cloud/dataform_v1beta1}/gapic_version.py +1 -1
  8. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/dataform/client.py +32 -14
  9. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0/google_cloud_dataform.egg-info}/PKG-INFO +1 -1
  10. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/tests/unit/gapic/dataform_v1/test_dataform.py +226 -29
  11. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/tests/unit/gapic/dataform_v1beta1/test_dataform.py +226 -29
  12. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/LICENSE +0 -0
  13. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/MANIFEST.in +0 -0
  14. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/README.rst +0 -0
  15. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform/__init__.py +0 -0
  16. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform/py.typed +0 -0
  17. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/gapic_metadata.json +0 -0
  18. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/py.typed +0 -0
  19. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/__init__.py +0 -0
  20. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/dataform/__init__.py +0 -0
  21. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/dataform/async_client.py +0 -0
  22. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/dataform/pagers.py +0 -0
  23. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/dataform/transports/__init__.py +0 -0
  24. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/dataform/transports/base.py +0 -0
  25. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/dataform/transports/grpc.py +0 -0
  26. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/dataform/transports/grpc_asyncio.py +0 -0
  27. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/dataform/transports/rest.py +0 -0
  28. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/services/dataform/transports/rest_base.py +0 -0
  29. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/types/__init__.py +0 -0
  30. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1/types/dataform.py +0 -0
  31. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/gapic_metadata.json +0 -0
  32. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/py.typed +0 -0
  33. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/__init__.py +0 -0
  34. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/dataform/__init__.py +0 -0
  35. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/dataform/async_client.py +0 -0
  36. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/dataform/pagers.py +0 -0
  37. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/dataform/transports/__init__.py +0 -0
  38. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/dataform/transports/base.py +0 -0
  39. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/dataform/transports/grpc.py +0 -0
  40. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/dataform/transports/grpc_asyncio.py +0 -0
  41. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/dataform/transports/rest.py +0 -0
  42. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/services/dataform/transports/rest_base.py +0 -0
  43. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/types/__init__.py +0 -0
  44. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google/cloud/dataform_v1beta1/types/dataform.py +0 -0
  45. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google_cloud_dataform.egg-info/SOURCES.txt +0 -0
  46. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google_cloud_dataform.egg-info/dependency_links.txt +0 -0
  47. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google_cloud_dataform.egg-info/not-zip-safe +0 -0
  48. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google_cloud_dataform.egg-info/requires.txt +0 -0
  49. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/google_cloud_dataform.egg-info/top_level.txt +0 -0
  50. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/setup.cfg +0 -0
  51. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/setup.py +0 -0
  52. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/tests/__init__.py +0 -0
  53. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/tests/unit/__init__.py +0 -0
  54. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/tests/unit/gapic/__init__.py +0 -0
  55. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/tests/unit/gapic/dataform_v1/__init__.py +0 -0
  56. {google_cloud_dataform-0.7.0 → google_cloud_dataform-0.8.0}/tests/unit/gapic/dataform_v1beta1/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: google-cloud-dataform
3
- Version: 0.7.0
3
+ Version: 0.8.0
4
4
  Summary: Google Cloud Dataform API client library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-dataform
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.7.0" # {x-release-please-version}
16
+ __version__ = "0.8.0" # {x-release-please-version}
@@ -13,10 +13,20 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
+ import sys
17
+
18
+ import google.api_core as api_core
19
+
16
20
  from google.cloud.dataform_v1 import gapic_version as package_version
17
21
 
18
22
  __version__ = package_version.__version__
19
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
20
30
 
21
31
  from .services.dataform import DataformAsyncClient, DataformClient
22
32
  from .types.dataform import (
@@ -130,6 +140,100 @@ from .types.dataform import (
130
140
  WriteFileResponse,
131
141
  )
132
142
 
143
+ if hasattr(api_core, "check_python_version") and hasattr(
144
+ api_core, "check_dependency_versions"
145
+ ): # pragma: NO COVER
146
+ api_core.check_python_version("google.cloud.dataform_v1") # type: ignore
147
+ api_core.check_dependency_versions("google.cloud.dataform_v1") # type: ignore
148
+ else: # pragma: NO COVER
149
+ # An older version of api_core is installed which does not define the
150
+ # functions above. We do equivalent checks manually.
151
+ try:
152
+ import sys
153
+ import warnings
154
+
155
+ _py_version_str = sys.version.split()[0]
156
+ _package_label = "google.cloud.dataform_v1"
157
+ if sys.version_info < (3, 9):
158
+ warnings.warn(
159
+ "You are using a non-supported Python version "
160
+ + f"({_py_version_str}). Google will not post any further "
161
+ + f"updates to {_package_label} supporting this Python version. "
162
+ + "Please upgrade to the latest Python version, or at "
163
+ + f"least to Python 3.9, and then update {_package_label}.",
164
+ FutureWarning,
165
+ )
166
+ if sys.version_info[:2] == (3, 9):
167
+ warnings.warn(
168
+ f"You are using a Python version ({_py_version_str}) "
169
+ + f"which Google will stop supporting in {_package_label} in "
170
+ + "January 2026. Please "
171
+ + "upgrade to the latest Python version, or at "
172
+ + "least to Python 3.10, before then, and "
173
+ + f"then update {_package_label}.",
174
+ FutureWarning,
175
+ )
176
+
177
+ def parse_version_to_tuple(version_string: str):
178
+ """Safely converts a semantic version string to a comparable tuple of integers.
179
+ Example: "4.25.8" -> (4, 25, 8)
180
+ Ignores non-numeric parts and handles common version formats.
181
+ Args:
182
+ version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
183
+ Returns:
184
+ Tuple of integers for the parsed version string.
185
+ """
186
+ parts = []
187
+ for part in version_string.split("."):
188
+ try:
189
+ parts.append(int(part))
190
+ except ValueError:
191
+ # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
192
+ # This is a simplification compared to 'packaging.parse_version', but sufficient
193
+ # for comparing strictly numeric semantic versions.
194
+ break
195
+ return tuple(parts)
196
+
197
+ def _get_version(dependency_name):
198
+ try:
199
+ version_string: str = metadata.version(dependency_name)
200
+ parsed_version = parse_version_to_tuple(version_string)
201
+ return (parsed_version, version_string)
202
+ except Exception:
203
+ # Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
204
+ # or errors during parse_version_to_tuple
205
+ return (None, "--")
206
+
207
+ _dependency_package = "google.protobuf"
208
+ _next_supported_version = "4.25.8"
209
+ _next_supported_version_tuple = (4, 25, 8)
210
+ _recommendation = " (we recommend 6.x)"
211
+ (_version_used, _version_used_string) = _get_version(_dependency_package)
212
+ if _version_used and _version_used < _next_supported_version_tuple:
213
+ warnings.warn(
214
+ f"Package {_package_label} depends on "
215
+ + f"{_dependency_package}, currently installed at version "
216
+ + f"{_version_used_string}. Future updates to "
217
+ + f"{_package_label} will require {_dependency_package} at "
218
+ + f"version {_next_supported_version} or higher{_recommendation}."
219
+ + " Please ensure "
220
+ + "that either (a) your Python environment doesn't pin the "
221
+ + f"version of {_dependency_package}, so that updates to "
222
+ + f"{_package_label} can require the higher version, or "
223
+ + "(b) you manually update your Python environment to use at "
224
+ + f"least version {_next_supported_version} of "
225
+ + f"{_dependency_package}.",
226
+ FutureWarning,
227
+ )
228
+ except Exception:
229
+ warnings.warn(
230
+ "Could not determine the version of Python "
231
+ + "currently being used. To continue receiving "
232
+ + "updates for {_package_label}, ensure you are "
233
+ + "using a supported version of Python; see "
234
+ + "https://devguide.python.org/versions/"
235
+ )
236
+
133
237
  __all__ = (
134
238
  "DataformAsyncClient",
135
239
  "CancelWorkflowInvocationRequest",
@@ -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.7.0" # {x-release-please-version}
16
+ __version__ = "0.8.0" # {x-release-please-version}
@@ -156,6 +156,34 @@ class DataformClient(metaclass=DataformClientMeta):
156
156
  _DEFAULT_ENDPOINT_TEMPLATE = "dataform.{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
@@ -578,12 +606,8 @@ class DataformClient(metaclass=DataformClientMeta):
578
606
  )
579
607
  if client_options is None:
580
608
  client_options = client_options_lib.ClientOptions()
581
- use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
609
+ use_client_cert = DataformClient._use_client_cert_effective()
582
610
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
583
- if use_client_cert not in ("true", "false"):
584
- raise ValueError(
585
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
586
- )
587
611
  if use_mtls_endpoint not in ("auto", "never", "always"):
588
612
  raise MutualTLSChannelError(
589
613
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
@@ -591,7 +615,7 @@ class DataformClient(metaclass=DataformClientMeta):
591
615
 
592
616
  # Figure out the client cert source to use.
593
617
  client_cert_source = None
594
- if use_client_cert == "true":
618
+ if use_client_cert:
595
619
  if client_options.client_cert_source:
596
620
  client_cert_source = client_options.client_cert_source
597
621
  elif mtls.has_default_client_cert_source():
@@ -623,20 +647,14 @@ class DataformClient(metaclass=DataformClientMeta):
623
647
  google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
624
648
  is not any of ["auto", "never", "always"].
625
649
  """
626
- use_client_cert = os.getenv(
627
- "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
628
- ).lower()
650
+ use_client_cert = DataformClient._use_client_cert_effective()
629
651
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
630
652
  universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
631
- if use_client_cert not in ("true", "false"):
632
- raise ValueError(
633
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
634
- )
635
653
  if use_mtls_endpoint not in ("auto", "never", "always"):
636
654
  raise MutualTLSChannelError(
637
655
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
638
656
  )
639
- return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
657
+ return use_client_cert, use_mtls_endpoint, universe_domain_env
640
658
 
641
659
  @staticmethod
642
660
  def _get_client_cert_source(provided_cert_source, use_cert_flag):
@@ -13,10 +13,20 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
+ import sys
17
+
18
+ import google.api_core as api_core
19
+
16
20
  from google.cloud.dataform_v1beta1 import gapic_version as package_version
17
21
 
18
22
  __version__ = package_version.__version__
19
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
20
30
 
21
31
  from .services.dataform import DataformAsyncClient, DataformClient
22
32
  from .types.dataform import (
@@ -130,6 +140,100 @@ from .types.dataform import (
130
140
  WriteFileResponse,
131
141
  )
132
142
 
143
+ if hasattr(api_core, "check_python_version") and hasattr(
144
+ api_core, "check_dependency_versions"
145
+ ): # pragma: NO COVER
146
+ api_core.check_python_version("google.cloud.dataform_v1beta1") # type: ignore
147
+ api_core.check_dependency_versions("google.cloud.dataform_v1beta1") # type: ignore
148
+ else: # pragma: NO COVER
149
+ # An older version of api_core is installed which does not define the
150
+ # functions above. We do equivalent checks manually.
151
+ try:
152
+ import sys
153
+ import warnings
154
+
155
+ _py_version_str = sys.version.split()[0]
156
+ _package_label = "google.cloud.dataform_v1beta1"
157
+ if sys.version_info < (3, 9):
158
+ warnings.warn(
159
+ "You are using a non-supported Python version "
160
+ + f"({_py_version_str}). Google will not post any further "
161
+ + f"updates to {_package_label} supporting this Python version. "
162
+ + "Please upgrade to the latest Python version, or at "
163
+ + f"least to Python 3.9, and then update {_package_label}.",
164
+ FutureWarning,
165
+ )
166
+ if sys.version_info[:2] == (3, 9):
167
+ warnings.warn(
168
+ f"You are using a Python version ({_py_version_str}) "
169
+ + f"which Google will stop supporting in {_package_label} in "
170
+ + "January 2026. Please "
171
+ + "upgrade to the latest Python version, or at "
172
+ + "least to Python 3.10, before then, and "
173
+ + f"then update {_package_label}.",
174
+ FutureWarning,
175
+ )
176
+
177
+ def parse_version_to_tuple(version_string: str):
178
+ """Safely converts a semantic version string to a comparable tuple of integers.
179
+ Example: "4.25.8" -> (4, 25, 8)
180
+ Ignores non-numeric parts and handles common version formats.
181
+ Args:
182
+ version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
183
+ Returns:
184
+ Tuple of integers for the parsed version string.
185
+ """
186
+ parts = []
187
+ for part in version_string.split("."):
188
+ try:
189
+ parts.append(int(part))
190
+ except ValueError:
191
+ # If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
192
+ # This is a simplification compared to 'packaging.parse_version', but sufficient
193
+ # for comparing strictly numeric semantic versions.
194
+ break
195
+ return tuple(parts)
196
+
197
+ def _get_version(dependency_name):
198
+ try:
199
+ version_string: str = metadata.version(dependency_name)
200
+ parsed_version = parse_version_to_tuple(version_string)
201
+ return (parsed_version, version_string)
202
+ except Exception:
203
+ # Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
204
+ # or errors during parse_version_to_tuple
205
+ return (None, "--")
206
+
207
+ _dependency_package = "google.protobuf"
208
+ _next_supported_version = "4.25.8"
209
+ _next_supported_version_tuple = (4, 25, 8)
210
+ _recommendation = " (we recommend 6.x)"
211
+ (_version_used, _version_used_string) = _get_version(_dependency_package)
212
+ if _version_used and _version_used < _next_supported_version_tuple:
213
+ warnings.warn(
214
+ f"Package {_package_label} depends on "
215
+ + f"{_dependency_package}, currently installed at version "
216
+ + f"{_version_used_string}. Future updates to "
217
+ + f"{_package_label} will require {_dependency_package} at "
218
+ + f"version {_next_supported_version} or higher{_recommendation}."
219
+ + " Please ensure "
220
+ + "that either (a) your Python environment doesn't pin the "
221
+ + f"version of {_dependency_package}, so that updates to "
222
+ + f"{_package_label} can require the higher version, or "
223
+ + "(b) you manually update your Python environment to use at "
224
+ + f"least version {_next_supported_version} of "
225
+ + f"{_dependency_package}.",
226
+ FutureWarning,
227
+ )
228
+ except Exception:
229
+ warnings.warn(
230
+ "Could not determine the version of Python "
231
+ + "currently being used. To continue receiving "
232
+ + "updates for {_package_label}, ensure you are "
233
+ + "using a supported version of Python; see "
234
+ + "https://devguide.python.org/versions/"
235
+ )
236
+
133
237
  __all__ = (
134
238
  "DataformAsyncClient",
135
239
  "CancelWorkflowInvocationRequest",
@@ -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.7.0" # {x-release-please-version}
16
+ __version__ = "0.8.0" # {x-release-please-version}
@@ -156,6 +156,34 @@ class DataformClient(metaclass=DataformClientMeta):
156
156
  _DEFAULT_ENDPOINT_TEMPLATE = "dataform.{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
@@ -578,12 +606,8 @@ class DataformClient(metaclass=DataformClientMeta):
578
606
  )
579
607
  if client_options is None:
580
608
  client_options = client_options_lib.ClientOptions()
581
- use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
609
+ use_client_cert = DataformClient._use_client_cert_effective()
582
610
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
583
- if use_client_cert not in ("true", "false"):
584
- raise ValueError(
585
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
586
- )
587
611
  if use_mtls_endpoint not in ("auto", "never", "always"):
588
612
  raise MutualTLSChannelError(
589
613
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
@@ -591,7 +615,7 @@ class DataformClient(metaclass=DataformClientMeta):
591
615
 
592
616
  # Figure out the client cert source to use.
593
617
  client_cert_source = None
594
- if use_client_cert == "true":
618
+ if use_client_cert:
595
619
  if client_options.client_cert_source:
596
620
  client_cert_source = client_options.client_cert_source
597
621
  elif mtls.has_default_client_cert_source():
@@ -623,20 +647,14 @@ class DataformClient(metaclass=DataformClientMeta):
623
647
  google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
624
648
  is not any of ["auto", "never", "always"].
625
649
  """
626
- use_client_cert = os.getenv(
627
- "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
628
- ).lower()
650
+ use_client_cert = DataformClient._use_client_cert_effective()
629
651
  use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
630
652
  universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
631
- if use_client_cert not in ("true", "false"):
632
- raise ValueError(
633
- "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
634
- )
635
653
  if use_mtls_endpoint not in ("auto", "never", "always"):
636
654
  raise MutualTLSChannelError(
637
655
  "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
638
656
  )
639
- return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
657
+ return use_client_cert, use_mtls_endpoint, universe_domain_env
640
658
 
641
659
  @staticmethod
642
660
  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-dataform
3
- Version: 0.7.0
3
+ Version: 0.8.0
4
4
  Summary: Google Cloud Dataform API client library
5
5
  Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-dataform
6
6
  Author: Google LLC
@@ -153,12 +153,19 @@ def test__read_environment_variables():
153
153
  with mock.patch.dict(
154
154
  os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
155
155
  ):
156
- with pytest.raises(ValueError) as excinfo:
157
- DataformClient._read_environment_variables()
158
- assert (
159
- str(excinfo.value)
160
- == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
161
- )
156
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
157
+ with pytest.raises(ValueError) as excinfo:
158
+ DataformClient._read_environment_variables()
159
+ assert (
160
+ str(excinfo.value)
161
+ == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
162
+ )
163
+ else:
164
+ assert DataformClient._read_environment_variables() == (
165
+ False,
166
+ "auto",
167
+ None,
168
+ )
162
169
 
163
170
  with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
164
171
  assert DataformClient._read_environment_variables() == (False, "never", None)
@@ -185,6 +192,105 @@ def test__read_environment_variables():
185
192
  )
186
193
 
187
194
 
195
+ def test_use_client_cert_effective():
196
+ # Test case 1: Test when `should_use_client_cert` returns True.
197
+ # We mock the `should_use_client_cert` function to simulate a scenario where
198
+ # the google-auth library supports automatic mTLS and determines that a
199
+ # client certificate should be used.
200
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
201
+ with mock.patch(
202
+ "google.auth.transport.mtls.should_use_client_cert", return_value=True
203
+ ):
204
+ assert DataformClient._use_client_cert_effective() is True
205
+
206
+ # Test case 2: Test when `should_use_client_cert` returns False.
207
+ # We mock the `should_use_client_cert` function to simulate a scenario where
208
+ # the google-auth library supports automatic mTLS and determines that a
209
+ # client certificate should NOT be used.
210
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
211
+ with mock.patch(
212
+ "google.auth.transport.mtls.should_use_client_cert", return_value=False
213
+ ):
214
+ assert DataformClient._use_client_cert_effective() is False
215
+
216
+ # Test case 3: Test when `should_use_client_cert` is unavailable and the
217
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "true".
218
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
219
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
220
+ assert DataformClient._use_client_cert_effective() is True
221
+
222
+ # Test case 4: Test when `should_use_client_cert` is unavailable and the
223
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "false".
224
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
225
+ with mock.patch.dict(
226
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}
227
+ ):
228
+ assert DataformClient._use_client_cert_effective() is False
229
+
230
+ # Test case 5: Test when `should_use_client_cert` is unavailable and the
231
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "True".
232
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
233
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "True"}):
234
+ assert DataformClient._use_client_cert_effective() is True
235
+
236
+ # Test case 6: Test when `should_use_client_cert` is unavailable and the
237
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "False".
238
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
239
+ with mock.patch.dict(
240
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "False"}
241
+ ):
242
+ assert DataformClient._use_client_cert_effective() is False
243
+
244
+ # Test case 7: Test when `should_use_client_cert` is unavailable and the
245
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "TRUE".
246
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
247
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "TRUE"}):
248
+ assert DataformClient._use_client_cert_effective() is True
249
+
250
+ # Test case 8: Test when `should_use_client_cert` is unavailable and the
251
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "FALSE".
252
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
253
+ with mock.patch.dict(
254
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "FALSE"}
255
+ ):
256
+ assert DataformClient._use_client_cert_effective() is False
257
+
258
+ # Test case 9: Test when `should_use_client_cert` is unavailable and the
259
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not set.
260
+ # In this case, the method should return False, which is the default value.
261
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
262
+ with mock.patch.dict(os.environ, clear=True):
263
+ assert DataformClient._use_client_cert_effective() is False
264
+
265
+ # Test case 10: Test when `should_use_client_cert` is unavailable and the
266
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
267
+ # The method should raise a ValueError as the environment variable must be either
268
+ # "true" or "false".
269
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
270
+ with mock.patch.dict(
271
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}
272
+ ):
273
+ with pytest.raises(ValueError):
274
+ DataformClient._use_client_cert_effective()
275
+
276
+ # Test case 11: Test when `should_use_client_cert` is available and the
277
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
278
+ # The method should return False as the environment variable is set to an invalid value.
279
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
280
+ with mock.patch.dict(
281
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}
282
+ ):
283
+ assert DataformClient._use_client_cert_effective() is False
284
+
285
+ # Test case 12: Test when `should_use_client_cert` is available and the
286
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is unset. Also,
287
+ # the GOOGLE_API_CONFIG environment variable is unset.
288
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
289
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": ""}):
290
+ with mock.patch.dict(os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": ""}):
291
+ assert DataformClient._use_client_cert_effective() is False
292
+
293
+
188
294
  def test__get_client_cert_source():
189
295
  mock_provided_cert_source = mock.Mock()
190
296
  mock_default_cert_source = mock.Mock()
@@ -541,17 +647,6 @@ def test_dataform_client_client_options(client_class, transport_class, transport
541
647
  == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
542
648
  )
543
649
 
544
- # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
545
- with mock.patch.dict(
546
- os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
547
- ):
548
- with pytest.raises(ValueError) as excinfo:
549
- client = client_class(transport=transport_name)
550
- assert (
551
- str(excinfo.value)
552
- == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
553
- )
554
-
555
650
  # Check the case quota_project_id is provided
556
651
  options = client_options.ClientOptions(quota_project_id="octopus")
557
652
  with mock.patch.object(transport_class, "__init__") as patched:
@@ -763,6 +858,119 @@ def test_dataform_client_get_mtls_endpoint_and_cert_source(client_class):
763
858
  assert api_endpoint == mock_api_endpoint
764
859
  assert cert_source is None
765
860
 
861
+ # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "Unsupported".
862
+ with mock.patch.dict(
863
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
864
+ ):
865
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
866
+ mock_client_cert_source = mock.Mock()
867
+ mock_api_endpoint = "foo"
868
+ options = client_options.ClientOptions(
869
+ client_cert_source=mock_client_cert_source,
870
+ api_endpoint=mock_api_endpoint,
871
+ )
872
+ api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(
873
+ options
874
+ )
875
+ assert api_endpoint == mock_api_endpoint
876
+ assert cert_source is None
877
+
878
+ # Test cases for mTLS enablement when GOOGLE_API_USE_CLIENT_CERTIFICATE is unset.
879
+ test_cases = [
880
+ (
881
+ # With workloads present in config, mTLS is enabled.
882
+ {
883
+ "version": 1,
884
+ "cert_configs": {
885
+ "workload": {
886
+ "cert_path": "path/to/cert/file",
887
+ "key_path": "path/to/key/file",
888
+ }
889
+ },
890
+ },
891
+ mock_client_cert_source,
892
+ ),
893
+ (
894
+ # With workloads not present in config, mTLS is disabled.
895
+ {
896
+ "version": 1,
897
+ "cert_configs": {},
898
+ },
899
+ None,
900
+ ),
901
+ ]
902
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
903
+ for config_data, expected_cert_source in test_cases:
904
+ env = os.environ.copy()
905
+ env.pop("GOOGLE_API_USE_CLIENT_CERTIFICATE", None)
906
+ with mock.patch.dict(os.environ, env, clear=True):
907
+ config_filename = "mock_certificate_config.json"
908
+ config_file_content = json.dumps(config_data)
909
+ m = mock.mock_open(read_data=config_file_content)
910
+ with mock.patch("builtins.open", m):
911
+ with mock.patch.dict(
912
+ os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": config_filename}
913
+ ):
914
+ mock_api_endpoint = "foo"
915
+ options = client_options.ClientOptions(
916
+ client_cert_source=mock_client_cert_source,
917
+ api_endpoint=mock_api_endpoint,
918
+ )
919
+ (
920
+ api_endpoint,
921
+ cert_source,
922
+ ) = client_class.get_mtls_endpoint_and_cert_source(options)
923
+ assert api_endpoint == mock_api_endpoint
924
+ assert cert_source is expected_cert_source
925
+
926
+ # Test cases for mTLS enablement when GOOGLE_API_USE_CLIENT_CERTIFICATE is unset(empty).
927
+ test_cases = [
928
+ (
929
+ # With workloads present in config, mTLS is enabled.
930
+ {
931
+ "version": 1,
932
+ "cert_configs": {
933
+ "workload": {
934
+ "cert_path": "path/to/cert/file",
935
+ "key_path": "path/to/key/file",
936
+ }
937
+ },
938
+ },
939
+ mock_client_cert_source,
940
+ ),
941
+ (
942
+ # With workloads not present in config, mTLS is disabled.
943
+ {
944
+ "version": 1,
945
+ "cert_configs": {},
946
+ },
947
+ None,
948
+ ),
949
+ ]
950
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
951
+ for config_data, expected_cert_source in test_cases:
952
+ env = os.environ.copy()
953
+ env.pop("GOOGLE_API_USE_CLIENT_CERTIFICATE", "")
954
+ with mock.patch.dict(os.environ, env, clear=True):
955
+ config_filename = "mock_certificate_config.json"
956
+ config_file_content = json.dumps(config_data)
957
+ m = mock.mock_open(read_data=config_file_content)
958
+ with mock.patch("builtins.open", m):
959
+ with mock.patch.dict(
960
+ os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": config_filename}
961
+ ):
962
+ mock_api_endpoint = "foo"
963
+ options = client_options.ClientOptions(
964
+ client_cert_source=mock_client_cert_source,
965
+ api_endpoint=mock_api_endpoint,
966
+ )
967
+ (
968
+ api_endpoint,
969
+ cert_source,
970
+ ) = client_class.get_mtls_endpoint_and_cert_source(options)
971
+ assert api_endpoint == mock_api_endpoint
972
+ assert cert_source is expected_cert_source
973
+
766
974
  # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never".
767
975
  with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
768
976
  api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source()
@@ -813,18 +1021,6 @@ def test_dataform_client_get_mtls_endpoint_and_cert_source(client_class):
813
1021
  == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
814
1022
  )
815
1023
 
816
- # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
817
- with mock.patch.dict(
818
- os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
819
- ):
820
- with pytest.raises(ValueError) as excinfo:
821
- client_class.get_mtls_endpoint_and_cert_source()
822
-
823
- assert (
824
- str(excinfo.value)
825
- == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
826
- )
827
-
828
1024
 
829
1025
  @pytest.mark.parametrize("client_class", [DataformClient, DataformAsyncClient])
830
1026
  @mock.patch.object(
@@ -42350,6 +42546,7 @@ def test_dataform_grpc_asyncio_transport_channel():
42350
42546
 
42351
42547
  # Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are
42352
42548
  # removed from grpc/grpc_asyncio transport constructor.
42549
+ @pytest.mark.filterwarnings("ignore::FutureWarning")
42353
42550
  @pytest.mark.parametrize(
42354
42551
  "transport_class",
42355
42552
  [transports.DataformGrpcTransport, transports.DataformGrpcAsyncIOTransport],
@@ -153,12 +153,19 @@ def test__read_environment_variables():
153
153
  with mock.patch.dict(
154
154
  os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
155
155
  ):
156
- with pytest.raises(ValueError) as excinfo:
157
- DataformClient._read_environment_variables()
158
- assert (
159
- str(excinfo.value)
160
- == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
161
- )
156
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
157
+ with pytest.raises(ValueError) as excinfo:
158
+ DataformClient._read_environment_variables()
159
+ assert (
160
+ str(excinfo.value)
161
+ == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
162
+ )
163
+ else:
164
+ assert DataformClient._read_environment_variables() == (
165
+ False,
166
+ "auto",
167
+ None,
168
+ )
162
169
 
163
170
  with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
164
171
  assert DataformClient._read_environment_variables() == (False, "never", None)
@@ -185,6 +192,105 @@ def test__read_environment_variables():
185
192
  )
186
193
 
187
194
 
195
+ def test_use_client_cert_effective():
196
+ # Test case 1: Test when `should_use_client_cert` returns True.
197
+ # We mock the `should_use_client_cert` function to simulate a scenario where
198
+ # the google-auth library supports automatic mTLS and determines that a
199
+ # client certificate should be used.
200
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
201
+ with mock.patch(
202
+ "google.auth.transport.mtls.should_use_client_cert", return_value=True
203
+ ):
204
+ assert DataformClient._use_client_cert_effective() is True
205
+
206
+ # Test case 2: Test when `should_use_client_cert` returns False.
207
+ # We mock the `should_use_client_cert` function to simulate a scenario where
208
+ # the google-auth library supports automatic mTLS and determines that a
209
+ # client certificate should NOT be used.
210
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
211
+ with mock.patch(
212
+ "google.auth.transport.mtls.should_use_client_cert", return_value=False
213
+ ):
214
+ assert DataformClient._use_client_cert_effective() is False
215
+
216
+ # Test case 3: Test when `should_use_client_cert` is unavailable and the
217
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "true".
218
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
219
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
220
+ assert DataformClient._use_client_cert_effective() is True
221
+
222
+ # Test case 4: Test when `should_use_client_cert` is unavailable and the
223
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "false".
224
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
225
+ with mock.patch.dict(
226
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}
227
+ ):
228
+ assert DataformClient._use_client_cert_effective() is False
229
+
230
+ # Test case 5: Test when `should_use_client_cert` is unavailable and the
231
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "True".
232
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
233
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "True"}):
234
+ assert DataformClient._use_client_cert_effective() is True
235
+
236
+ # Test case 6: Test when `should_use_client_cert` is unavailable and the
237
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "False".
238
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
239
+ with mock.patch.dict(
240
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "False"}
241
+ ):
242
+ assert DataformClient._use_client_cert_effective() is False
243
+
244
+ # Test case 7: Test when `should_use_client_cert` is unavailable and the
245
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "TRUE".
246
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
247
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "TRUE"}):
248
+ assert DataformClient._use_client_cert_effective() is True
249
+
250
+ # Test case 8: Test when `should_use_client_cert` is unavailable and the
251
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "FALSE".
252
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
253
+ with mock.patch.dict(
254
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "FALSE"}
255
+ ):
256
+ assert DataformClient._use_client_cert_effective() is False
257
+
258
+ # Test case 9: Test when `should_use_client_cert` is unavailable and the
259
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not set.
260
+ # In this case, the method should return False, which is the default value.
261
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
262
+ with mock.patch.dict(os.environ, clear=True):
263
+ assert DataformClient._use_client_cert_effective() is False
264
+
265
+ # Test case 10: Test when `should_use_client_cert` is unavailable and the
266
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
267
+ # The method should raise a ValueError as the environment variable must be either
268
+ # "true" or "false".
269
+ if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
270
+ with mock.patch.dict(
271
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}
272
+ ):
273
+ with pytest.raises(ValueError):
274
+ DataformClient._use_client_cert_effective()
275
+
276
+ # Test case 11: Test when `should_use_client_cert` is available and the
277
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
278
+ # The method should return False as the environment variable is set to an invalid value.
279
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
280
+ with mock.patch.dict(
281
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}
282
+ ):
283
+ assert DataformClient._use_client_cert_effective() is False
284
+
285
+ # Test case 12: Test when `should_use_client_cert` is available and the
286
+ # `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is unset. Also,
287
+ # the GOOGLE_API_CONFIG environment variable is unset.
288
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
289
+ with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": ""}):
290
+ with mock.patch.dict(os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": ""}):
291
+ assert DataformClient._use_client_cert_effective() is False
292
+
293
+
188
294
  def test__get_client_cert_source():
189
295
  mock_provided_cert_source = mock.Mock()
190
296
  mock_default_cert_source = mock.Mock()
@@ -541,17 +647,6 @@ def test_dataform_client_client_options(client_class, transport_class, transport
541
647
  == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
542
648
  )
543
649
 
544
- # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
545
- with mock.patch.dict(
546
- os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
547
- ):
548
- with pytest.raises(ValueError) as excinfo:
549
- client = client_class(transport=transport_name)
550
- assert (
551
- str(excinfo.value)
552
- == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
553
- )
554
-
555
650
  # Check the case quota_project_id is provided
556
651
  options = client_options.ClientOptions(quota_project_id="octopus")
557
652
  with mock.patch.object(transport_class, "__init__") as patched:
@@ -763,6 +858,119 @@ def test_dataform_client_get_mtls_endpoint_and_cert_source(client_class):
763
858
  assert api_endpoint == mock_api_endpoint
764
859
  assert cert_source is None
765
860
 
861
+ # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "Unsupported".
862
+ with mock.patch.dict(
863
+ os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
864
+ ):
865
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
866
+ mock_client_cert_source = mock.Mock()
867
+ mock_api_endpoint = "foo"
868
+ options = client_options.ClientOptions(
869
+ client_cert_source=mock_client_cert_source,
870
+ api_endpoint=mock_api_endpoint,
871
+ )
872
+ api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(
873
+ options
874
+ )
875
+ assert api_endpoint == mock_api_endpoint
876
+ assert cert_source is None
877
+
878
+ # Test cases for mTLS enablement when GOOGLE_API_USE_CLIENT_CERTIFICATE is unset.
879
+ test_cases = [
880
+ (
881
+ # With workloads present in config, mTLS is enabled.
882
+ {
883
+ "version": 1,
884
+ "cert_configs": {
885
+ "workload": {
886
+ "cert_path": "path/to/cert/file",
887
+ "key_path": "path/to/key/file",
888
+ }
889
+ },
890
+ },
891
+ mock_client_cert_source,
892
+ ),
893
+ (
894
+ # With workloads not present in config, mTLS is disabled.
895
+ {
896
+ "version": 1,
897
+ "cert_configs": {},
898
+ },
899
+ None,
900
+ ),
901
+ ]
902
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
903
+ for config_data, expected_cert_source in test_cases:
904
+ env = os.environ.copy()
905
+ env.pop("GOOGLE_API_USE_CLIENT_CERTIFICATE", None)
906
+ with mock.patch.dict(os.environ, env, clear=True):
907
+ config_filename = "mock_certificate_config.json"
908
+ config_file_content = json.dumps(config_data)
909
+ m = mock.mock_open(read_data=config_file_content)
910
+ with mock.patch("builtins.open", m):
911
+ with mock.patch.dict(
912
+ os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": config_filename}
913
+ ):
914
+ mock_api_endpoint = "foo"
915
+ options = client_options.ClientOptions(
916
+ client_cert_source=mock_client_cert_source,
917
+ api_endpoint=mock_api_endpoint,
918
+ )
919
+ (
920
+ api_endpoint,
921
+ cert_source,
922
+ ) = client_class.get_mtls_endpoint_and_cert_source(options)
923
+ assert api_endpoint == mock_api_endpoint
924
+ assert cert_source is expected_cert_source
925
+
926
+ # Test cases for mTLS enablement when GOOGLE_API_USE_CLIENT_CERTIFICATE is unset(empty).
927
+ test_cases = [
928
+ (
929
+ # With workloads present in config, mTLS is enabled.
930
+ {
931
+ "version": 1,
932
+ "cert_configs": {
933
+ "workload": {
934
+ "cert_path": "path/to/cert/file",
935
+ "key_path": "path/to/key/file",
936
+ }
937
+ },
938
+ },
939
+ mock_client_cert_source,
940
+ ),
941
+ (
942
+ # With workloads not present in config, mTLS is disabled.
943
+ {
944
+ "version": 1,
945
+ "cert_configs": {},
946
+ },
947
+ None,
948
+ ),
949
+ ]
950
+ if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
951
+ for config_data, expected_cert_source in test_cases:
952
+ env = os.environ.copy()
953
+ env.pop("GOOGLE_API_USE_CLIENT_CERTIFICATE", "")
954
+ with mock.patch.dict(os.environ, env, clear=True):
955
+ config_filename = "mock_certificate_config.json"
956
+ config_file_content = json.dumps(config_data)
957
+ m = mock.mock_open(read_data=config_file_content)
958
+ with mock.patch("builtins.open", m):
959
+ with mock.patch.dict(
960
+ os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": config_filename}
961
+ ):
962
+ mock_api_endpoint = "foo"
963
+ options = client_options.ClientOptions(
964
+ client_cert_source=mock_client_cert_source,
965
+ api_endpoint=mock_api_endpoint,
966
+ )
967
+ (
968
+ api_endpoint,
969
+ cert_source,
970
+ ) = client_class.get_mtls_endpoint_and_cert_source(options)
971
+ assert api_endpoint == mock_api_endpoint
972
+ assert cert_source is expected_cert_source
973
+
766
974
  # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never".
767
975
  with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
768
976
  api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source()
@@ -813,18 +1021,6 @@ def test_dataform_client_get_mtls_endpoint_and_cert_source(client_class):
813
1021
  == "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
814
1022
  )
815
1023
 
816
- # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
817
- with mock.patch.dict(
818
- os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
819
- ):
820
- with pytest.raises(ValueError) as excinfo:
821
- client_class.get_mtls_endpoint_and_cert_source()
822
-
823
- assert (
824
- str(excinfo.value)
825
- == "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
826
- )
827
-
828
1024
 
829
1025
  @pytest.mark.parametrize("client_class", [DataformClient, DataformAsyncClient])
830
1026
  @mock.patch.object(
@@ -42350,6 +42546,7 @@ def test_dataform_grpc_asyncio_transport_channel():
42350
42546
 
42351
42547
  # Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are
42352
42548
  # removed from grpc/grpc_asyncio transport constructor.
42549
+ @pytest.mark.filterwarnings("ignore::FutureWarning")
42353
42550
  @pytest.mark.parametrize(
42354
42551
  "transport_class",
42355
42552
  [transports.DataformGrpcTransport, transports.DataformGrpcAsyncIOTransport],