google-cloud-securesourcemanager 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.
- {google_cloud_securesourcemanager-0.2.0/google_cloud_securesourcemanager.egg-info → google_cloud_securesourcemanager-0.3.0}/PKG-INFO +1 -1
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager/gapic_version.py +1 -1
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/__init__.py +104 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/gapic_version.py +1 -1
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/secure_source_manager/client.py +32 -14
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0/google_cloud_securesourcemanager.egg-info}/PKG-INFO +1 -1
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/tests/unit/gapic/securesourcemanager_v1/test_secure_source_manager.py +226 -29
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/LICENSE +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/MANIFEST.in +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/README.rst +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager/__init__.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager/py.typed +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/gapic_metadata.json +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/py.typed +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/__init__.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/secure_source_manager/__init__.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/secure_source_manager/async_client.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/secure_source_manager/pagers.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/secure_source_manager/transports/__init__.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/secure_source_manager/transports/base.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/secure_source_manager/transports/grpc.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/secure_source_manager/transports/grpc_asyncio.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/secure_source_manager/transports/rest.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/services/secure_source_manager/transports/rest_base.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/types/__init__.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google/cloud/securesourcemanager_v1/types/secure_source_manager.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google_cloud_securesourcemanager.egg-info/SOURCES.txt +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google_cloud_securesourcemanager.egg-info/dependency_links.txt +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google_cloud_securesourcemanager.egg-info/not-zip-safe +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google_cloud_securesourcemanager.egg-info/requires.txt +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/google_cloud_securesourcemanager.egg-info/top_level.txt +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/setup.cfg +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/setup.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/tests/__init__.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/tests/unit/__init__.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/tests/unit/gapic/__init__.py +0 -0
- {google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/tests/unit/gapic/securesourcemanager_v1/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: google-cloud-securesourcemanager
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Google Cloud Securesourcemanager API client library
|
|
5
5
|
Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-securesourcemanager
|
|
6
6
|
Author: Google LLC
|
|
@@ -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.securesourcemanager_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.secure_source_manager import (
|
|
22
32
|
SecureSourceManagerAsyncClient,
|
|
@@ -99,6 +109,100 @@ from .types.secure_source_manager import (
|
|
|
99
109
|
UpdateRepositoryRequest,
|
|
100
110
|
)
|
|
101
111
|
|
|
112
|
+
if hasattr(api_core, "check_python_version") and hasattr(
|
|
113
|
+
api_core, "check_dependency_versions"
|
|
114
|
+
): # pragma: NO COVER
|
|
115
|
+
api_core.check_python_version("google.cloud.securesourcemanager_v1") # type: ignore
|
|
116
|
+
api_core.check_dependency_versions("google.cloud.securesourcemanager_v1") # type: ignore
|
|
117
|
+
else: # pragma: NO COVER
|
|
118
|
+
# An older version of api_core is installed which does not define the
|
|
119
|
+
# functions above. We do equivalent checks manually.
|
|
120
|
+
try:
|
|
121
|
+
import sys
|
|
122
|
+
import warnings
|
|
123
|
+
|
|
124
|
+
_py_version_str = sys.version.split()[0]
|
|
125
|
+
_package_label = "google.cloud.securesourcemanager_v1"
|
|
126
|
+
if sys.version_info < (3, 9):
|
|
127
|
+
warnings.warn(
|
|
128
|
+
"You are using a non-supported Python version "
|
|
129
|
+
+ f"({_py_version_str}). Google will not post any further "
|
|
130
|
+
+ f"updates to {_package_label} supporting this Python version. "
|
|
131
|
+
+ "Please upgrade to the latest Python version, or at "
|
|
132
|
+
+ f"least to Python 3.9, and then update {_package_label}.",
|
|
133
|
+
FutureWarning,
|
|
134
|
+
)
|
|
135
|
+
if sys.version_info[:2] == (3, 9):
|
|
136
|
+
warnings.warn(
|
|
137
|
+
f"You are using a Python version ({_py_version_str}) "
|
|
138
|
+
+ f"which Google will stop supporting in {_package_label} in "
|
|
139
|
+
+ "January 2026. Please "
|
|
140
|
+
+ "upgrade to the latest Python version, or at "
|
|
141
|
+
+ "least to Python 3.10, before then, and "
|
|
142
|
+
+ f"then update {_package_label}.",
|
|
143
|
+
FutureWarning,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def parse_version_to_tuple(version_string: str):
|
|
147
|
+
"""Safely converts a semantic version string to a comparable tuple of integers.
|
|
148
|
+
Example: "4.25.8" -> (4, 25, 8)
|
|
149
|
+
Ignores non-numeric parts and handles common version formats.
|
|
150
|
+
Args:
|
|
151
|
+
version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
|
|
152
|
+
Returns:
|
|
153
|
+
Tuple of integers for the parsed version string.
|
|
154
|
+
"""
|
|
155
|
+
parts = []
|
|
156
|
+
for part in version_string.split("."):
|
|
157
|
+
try:
|
|
158
|
+
parts.append(int(part))
|
|
159
|
+
except ValueError:
|
|
160
|
+
# If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
|
|
161
|
+
# This is a simplification compared to 'packaging.parse_version', but sufficient
|
|
162
|
+
# for comparing strictly numeric semantic versions.
|
|
163
|
+
break
|
|
164
|
+
return tuple(parts)
|
|
165
|
+
|
|
166
|
+
def _get_version(dependency_name):
|
|
167
|
+
try:
|
|
168
|
+
version_string: str = metadata.version(dependency_name)
|
|
169
|
+
parsed_version = parse_version_to_tuple(version_string)
|
|
170
|
+
return (parsed_version, version_string)
|
|
171
|
+
except Exception:
|
|
172
|
+
# Catch exceptions from metadata.version() (e.g., PackageNotFoundError)
|
|
173
|
+
# or errors during parse_version_to_tuple
|
|
174
|
+
return (None, "--")
|
|
175
|
+
|
|
176
|
+
_dependency_package = "google.protobuf"
|
|
177
|
+
_next_supported_version = "4.25.8"
|
|
178
|
+
_next_supported_version_tuple = (4, 25, 8)
|
|
179
|
+
_recommendation = " (we recommend 6.x)"
|
|
180
|
+
(_version_used, _version_used_string) = _get_version(_dependency_package)
|
|
181
|
+
if _version_used and _version_used < _next_supported_version_tuple:
|
|
182
|
+
warnings.warn(
|
|
183
|
+
f"Package {_package_label} depends on "
|
|
184
|
+
+ f"{_dependency_package}, currently installed at version "
|
|
185
|
+
+ f"{_version_used_string}. Future updates to "
|
|
186
|
+
+ f"{_package_label} will require {_dependency_package} at "
|
|
187
|
+
+ f"version {_next_supported_version} or higher{_recommendation}."
|
|
188
|
+
+ " Please ensure "
|
|
189
|
+
+ "that either (a) your Python environment doesn't pin the "
|
|
190
|
+
+ f"version of {_dependency_package}, so that updates to "
|
|
191
|
+
+ f"{_package_label} can require the higher version, or "
|
|
192
|
+
+ "(b) you manually update your Python environment to use at "
|
|
193
|
+
+ f"least version {_next_supported_version} of "
|
|
194
|
+
+ f"{_dependency_package}.",
|
|
195
|
+
FutureWarning,
|
|
196
|
+
)
|
|
197
|
+
except Exception:
|
|
198
|
+
warnings.warn(
|
|
199
|
+
"Could not determine the version of Python "
|
|
200
|
+
+ "currently being used. To continue receiving "
|
|
201
|
+
+ "updates for {_package_label}, ensure you are "
|
|
202
|
+
+ "using a supported version of Python; see "
|
|
203
|
+
+ "https://devguide.python.org/versions/"
|
|
204
|
+
)
|
|
205
|
+
|
|
102
206
|
__all__ = (
|
|
103
207
|
"SecureSourceManagerAsyncClient",
|
|
104
208
|
"BatchCreatePullRequestCommentsRequest",
|
|
@@ -163,6 +163,34 @@ class SecureSourceManagerClient(metaclass=SecureSourceManagerClientMeta):
|
|
|
163
163
|
_DEFAULT_ENDPOINT_TEMPLATE = "securesourcemanager.{UNIVERSE_DOMAIN}"
|
|
164
164
|
_DEFAULT_UNIVERSE = "googleapis.com"
|
|
165
165
|
|
|
166
|
+
@staticmethod
|
|
167
|
+
def _use_client_cert_effective():
|
|
168
|
+
"""Returns whether client certificate should be used for mTLS if the
|
|
169
|
+
google-auth version supports should_use_client_cert automatic mTLS enablement.
|
|
170
|
+
|
|
171
|
+
Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var.
|
|
172
|
+
|
|
173
|
+
Returns:
|
|
174
|
+
bool: whether client certificate should be used for mTLS
|
|
175
|
+
Raises:
|
|
176
|
+
ValueError: (If using a version of google-auth without should_use_client_cert and
|
|
177
|
+
GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.)
|
|
178
|
+
"""
|
|
179
|
+
# check if google-auth version supports should_use_client_cert for automatic mTLS enablement
|
|
180
|
+
if hasattr(mtls, "should_use_client_cert"): # pragma: NO COVER
|
|
181
|
+
return mtls.should_use_client_cert()
|
|
182
|
+
else: # pragma: NO COVER
|
|
183
|
+
# if unsupported, fallback to reading from env var
|
|
184
|
+
use_client_cert_str = os.getenv(
|
|
185
|
+
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
|
|
186
|
+
).lower()
|
|
187
|
+
if use_client_cert_str not in ("true", "false"):
|
|
188
|
+
raise ValueError(
|
|
189
|
+
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"
|
|
190
|
+
" either `true` or `false`"
|
|
191
|
+
)
|
|
192
|
+
return use_client_cert_str == "true"
|
|
193
|
+
|
|
166
194
|
@classmethod
|
|
167
195
|
def from_service_account_info(cls, info: dict, *args, **kwargs):
|
|
168
196
|
"""Creates an instance of this client using the provided credentials
|
|
@@ -590,12 +618,8 @@ class SecureSourceManagerClient(metaclass=SecureSourceManagerClientMeta):
|
|
|
590
618
|
)
|
|
591
619
|
if client_options is None:
|
|
592
620
|
client_options = client_options_lib.ClientOptions()
|
|
593
|
-
use_client_cert =
|
|
621
|
+
use_client_cert = SecureSourceManagerClient._use_client_cert_effective()
|
|
594
622
|
use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
|
|
595
|
-
if use_client_cert not in ("true", "false"):
|
|
596
|
-
raise ValueError(
|
|
597
|
-
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
|
|
598
|
-
)
|
|
599
623
|
if use_mtls_endpoint not in ("auto", "never", "always"):
|
|
600
624
|
raise MutualTLSChannelError(
|
|
601
625
|
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
|
|
@@ -603,7 +627,7 @@ class SecureSourceManagerClient(metaclass=SecureSourceManagerClientMeta):
|
|
|
603
627
|
|
|
604
628
|
# Figure out the client cert source to use.
|
|
605
629
|
client_cert_source = None
|
|
606
|
-
if use_client_cert
|
|
630
|
+
if use_client_cert:
|
|
607
631
|
if client_options.client_cert_source:
|
|
608
632
|
client_cert_source = client_options.client_cert_source
|
|
609
633
|
elif mtls.has_default_client_cert_source():
|
|
@@ -635,20 +659,14 @@ class SecureSourceManagerClient(metaclass=SecureSourceManagerClientMeta):
|
|
|
635
659
|
google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
|
|
636
660
|
is not any of ["auto", "never", "always"].
|
|
637
661
|
"""
|
|
638
|
-
use_client_cert =
|
|
639
|
-
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
|
|
640
|
-
).lower()
|
|
662
|
+
use_client_cert = SecureSourceManagerClient._use_client_cert_effective()
|
|
641
663
|
use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
|
|
642
664
|
universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
|
|
643
|
-
if use_client_cert not in ("true", "false"):
|
|
644
|
-
raise ValueError(
|
|
645
|
-
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
|
|
646
|
-
)
|
|
647
665
|
if use_mtls_endpoint not in ("auto", "never", "always"):
|
|
648
666
|
raise MutualTLSChannelError(
|
|
649
667
|
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
|
|
650
668
|
)
|
|
651
|
-
return use_client_cert
|
|
669
|
+
return use_client_cert, use_mtls_endpoint, universe_domain_env
|
|
652
670
|
|
|
653
671
|
@staticmethod
|
|
654
672
|
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-securesourcemanager
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Google Cloud Securesourcemanager API client library
|
|
5
5
|
Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-securesourcemanager
|
|
6
6
|
Author: Google LLC
|
|
@@ -180,12 +180,19 @@ def test__read_environment_variables():
|
|
|
180
180
|
with mock.patch.dict(
|
|
181
181
|
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
|
|
182
182
|
):
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
183
|
+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
184
|
+
with pytest.raises(ValueError) as excinfo:
|
|
185
|
+
SecureSourceManagerClient._read_environment_variables()
|
|
186
|
+
assert (
|
|
187
|
+
str(excinfo.value)
|
|
188
|
+
== "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
|
|
189
|
+
)
|
|
190
|
+
else:
|
|
191
|
+
assert SecureSourceManagerClient._read_environment_variables() == (
|
|
192
|
+
False,
|
|
193
|
+
"auto",
|
|
194
|
+
None,
|
|
195
|
+
)
|
|
189
196
|
|
|
190
197
|
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
|
|
191
198
|
assert SecureSourceManagerClient._read_environment_variables() == (
|
|
@@ -224,6 +231,105 @@ def test__read_environment_variables():
|
|
|
224
231
|
)
|
|
225
232
|
|
|
226
233
|
|
|
234
|
+
def test_use_client_cert_effective():
|
|
235
|
+
# Test case 1: Test when `should_use_client_cert` returns True.
|
|
236
|
+
# We mock the `should_use_client_cert` function to simulate a scenario where
|
|
237
|
+
# the google-auth library supports automatic mTLS and determines that a
|
|
238
|
+
# client certificate should be used.
|
|
239
|
+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
240
|
+
with mock.patch(
|
|
241
|
+
"google.auth.transport.mtls.should_use_client_cert", return_value=True
|
|
242
|
+
):
|
|
243
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is True
|
|
244
|
+
|
|
245
|
+
# Test case 2: Test when `should_use_client_cert` returns False.
|
|
246
|
+
# We mock the `should_use_client_cert` function to simulate a scenario where
|
|
247
|
+
# the google-auth library supports automatic mTLS and determines that a
|
|
248
|
+
# client certificate should NOT be used.
|
|
249
|
+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
250
|
+
with mock.patch(
|
|
251
|
+
"google.auth.transport.mtls.should_use_client_cert", return_value=False
|
|
252
|
+
):
|
|
253
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is False
|
|
254
|
+
|
|
255
|
+
# Test case 3: Test when `should_use_client_cert` is unavailable and the
|
|
256
|
+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "true".
|
|
257
|
+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
258
|
+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}):
|
|
259
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is True
|
|
260
|
+
|
|
261
|
+
# Test case 4: Test when `should_use_client_cert` is unavailable and the
|
|
262
|
+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "false".
|
|
263
|
+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
264
|
+
with mock.patch.dict(
|
|
265
|
+
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}
|
|
266
|
+
):
|
|
267
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is False
|
|
268
|
+
|
|
269
|
+
# Test case 5: Test when `should_use_client_cert` is unavailable and the
|
|
270
|
+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "True".
|
|
271
|
+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
272
|
+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "True"}):
|
|
273
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is True
|
|
274
|
+
|
|
275
|
+
# Test case 6: Test when `should_use_client_cert` is unavailable and the
|
|
276
|
+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "False".
|
|
277
|
+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
278
|
+
with mock.patch.dict(
|
|
279
|
+
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "False"}
|
|
280
|
+
):
|
|
281
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is False
|
|
282
|
+
|
|
283
|
+
# Test case 7: Test when `should_use_client_cert` is unavailable and the
|
|
284
|
+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "TRUE".
|
|
285
|
+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
286
|
+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "TRUE"}):
|
|
287
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is True
|
|
288
|
+
|
|
289
|
+
# Test case 8: Test when `should_use_client_cert` is unavailable and the
|
|
290
|
+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to "FALSE".
|
|
291
|
+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
292
|
+
with mock.patch.dict(
|
|
293
|
+
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "FALSE"}
|
|
294
|
+
):
|
|
295
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is False
|
|
296
|
+
|
|
297
|
+
# Test case 9: Test when `should_use_client_cert` is unavailable and the
|
|
298
|
+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not set.
|
|
299
|
+
# In this case, the method should return False, which is the default value.
|
|
300
|
+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
301
|
+
with mock.patch.dict(os.environ, clear=True):
|
|
302
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is False
|
|
303
|
+
|
|
304
|
+
# Test case 10: Test when `should_use_client_cert` is unavailable and the
|
|
305
|
+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
|
|
306
|
+
# The method should raise a ValueError as the environment variable must be either
|
|
307
|
+
# "true" or "false".
|
|
308
|
+
if not hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
309
|
+
with mock.patch.dict(
|
|
310
|
+
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}
|
|
311
|
+
):
|
|
312
|
+
with pytest.raises(ValueError):
|
|
313
|
+
SecureSourceManagerClient._use_client_cert_effective()
|
|
314
|
+
|
|
315
|
+
# Test case 11: Test when `should_use_client_cert` is available and the
|
|
316
|
+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is set to an invalid value.
|
|
317
|
+
# The method should return False as the environment variable is set to an invalid value.
|
|
318
|
+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
319
|
+
with mock.patch.dict(
|
|
320
|
+
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "unsupported"}
|
|
321
|
+
):
|
|
322
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is False
|
|
323
|
+
|
|
324
|
+
# Test case 12: Test when `should_use_client_cert` is available and the
|
|
325
|
+
# `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is unset. Also,
|
|
326
|
+
# the GOOGLE_API_CONFIG environment variable is unset.
|
|
327
|
+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
328
|
+
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": ""}):
|
|
329
|
+
with mock.patch.dict(os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": ""}):
|
|
330
|
+
assert SecureSourceManagerClient._use_client_cert_effective() is False
|
|
331
|
+
|
|
332
|
+
|
|
227
333
|
def test__get_client_cert_source():
|
|
228
334
|
mock_provided_cert_source = mock.Mock()
|
|
229
335
|
mock_default_cert_source = mock.Mock()
|
|
@@ -611,17 +717,6 @@ def test_secure_source_manager_client_client_options(
|
|
|
611
717
|
== "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
|
|
612
718
|
)
|
|
613
719
|
|
|
614
|
-
# Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
|
|
615
|
-
with mock.patch.dict(
|
|
616
|
-
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
|
|
617
|
-
):
|
|
618
|
-
with pytest.raises(ValueError) as excinfo:
|
|
619
|
-
client = client_class(transport=transport_name)
|
|
620
|
-
assert (
|
|
621
|
-
str(excinfo.value)
|
|
622
|
-
== "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
|
|
623
|
-
)
|
|
624
|
-
|
|
625
720
|
# Check the case quota_project_id is provided
|
|
626
721
|
options = client_options.ClientOptions(quota_project_id="octopus")
|
|
627
722
|
with mock.patch.object(transport_class, "__init__") as patched:
|
|
@@ -857,6 +952,119 @@ def test_secure_source_manager_client_get_mtls_endpoint_and_cert_source(client_c
|
|
|
857
952
|
assert api_endpoint == mock_api_endpoint
|
|
858
953
|
assert cert_source is None
|
|
859
954
|
|
|
955
|
+
# Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "Unsupported".
|
|
956
|
+
with mock.patch.dict(
|
|
957
|
+
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
|
|
958
|
+
):
|
|
959
|
+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
960
|
+
mock_client_cert_source = mock.Mock()
|
|
961
|
+
mock_api_endpoint = "foo"
|
|
962
|
+
options = client_options.ClientOptions(
|
|
963
|
+
client_cert_source=mock_client_cert_source,
|
|
964
|
+
api_endpoint=mock_api_endpoint,
|
|
965
|
+
)
|
|
966
|
+
api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source(
|
|
967
|
+
options
|
|
968
|
+
)
|
|
969
|
+
assert api_endpoint == mock_api_endpoint
|
|
970
|
+
assert cert_source is None
|
|
971
|
+
|
|
972
|
+
# Test cases for mTLS enablement when GOOGLE_API_USE_CLIENT_CERTIFICATE is unset.
|
|
973
|
+
test_cases = [
|
|
974
|
+
(
|
|
975
|
+
# With workloads present in config, mTLS is enabled.
|
|
976
|
+
{
|
|
977
|
+
"version": 1,
|
|
978
|
+
"cert_configs": {
|
|
979
|
+
"workload": {
|
|
980
|
+
"cert_path": "path/to/cert/file",
|
|
981
|
+
"key_path": "path/to/key/file",
|
|
982
|
+
}
|
|
983
|
+
},
|
|
984
|
+
},
|
|
985
|
+
mock_client_cert_source,
|
|
986
|
+
),
|
|
987
|
+
(
|
|
988
|
+
# With workloads not present in config, mTLS is disabled.
|
|
989
|
+
{
|
|
990
|
+
"version": 1,
|
|
991
|
+
"cert_configs": {},
|
|
992
|
+
},
|
|
993
|
+
None,
|
|
994
|
+
),
|
|
995
|
+
]
|
|
996
|
+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
997
|
+
for config_data, expected_cert_source in test_cases:
|
|
998
|
+
env = os.environ.copy()
|
|
999
|
+
env.pop("GOOGLE_API_USE_CLIENT_CERTIFICATE", None)
|
|
1000
|
+
with mock.patch.dict(os.environ, env, clear=True):
|
|
1001
|
+
config_filename = "mock_certificate_config.json"
|
|
1002
|
+
config_file_content = json.dumps(config_data)
|
|
1003
|
+
m = mock.mock_open(read_data=config_file_content)
|
|
1004
|
+
with mock.patch("builtins.open", m):
|
|
1005
|
+
with mock.patch.dict(
|
|
1006
|
+
os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": config_filename}
|
|
1007
|
+
):
|
|
1008
|
+
mock_api_endpoint = "foo"
|
|
1009
|
+
options = client_options.ClientOptions(
|
|
1010
|
+
client_cert_source=mock_client_cert_source,
|
|
1011
|
+
api_endpoint=mock_api_endpoint,
|
|
1012
|
+
)
|
|
1013
|
+
(
|
|
1014
|
+
api_endpoint,
|
|
1015
|
+
cert_source,
|
|
1016
|
+
) = client_class.get_mtls_endpoint_and_cert_source(options)
|
|
1017
|
+
assert api_endpoint == mock_api_endpoint
|
|
1018
|
+
assert cert_source is expected_cert_source
|
|
1019
|
+
|
|
1020
|
+
# Test cases for mTLS enablement when GOOGLE_API_USE_CLIENT_CERTIFICATE is unset(empty).
|
|
1021
|
+
test_cases = [
|
|
1022
|
+
(
|
|
1023
|
+
# With workloads present in config, mTLS is enabled.
|
|
1024
|
+
{
|
|
1025
|
+
"version": 1,
|
|
1026
|
+
"cert_configs": {
|
|
1027
|
+
"workload": {
|
|
1028
|
+
"cert_path": "path/to/cert/file",
|
|
1029
|
+
"key_path": "path/to/key/file",
|
|
1030
|
+
}
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1033
|
+
mock_client_cert_source,
|
|
1034
|
+
),
|
|
1035
|
+
(
|
|
1036
|
+
# With workloads not present in config, mTLS is disabled.
|
|
1037
|
+
{
|
|
1038
|
+
"version": 1,
|
|
1039
|
+
"cert_configs": {},
|
|
1040
|
+
},
|
|
1041
|
+
None,
|
|
1042
|
+
),
|
|
1043
|
+
]
|
|
1044
|
+
if hasattr(google.auth.transport.mtls, "should_use_client_cert"):
|
|
1045
|
+
for config_data, expected_cert_source in test_cases:
|
|
1046
|
+
env = os.environ.copy()
|
|
1047
|
+
env.pop("GOOGLE_API_USE_CLIENT_CERTIFICATE", "")
|
|
1048
|
+
with mock.patch.dict(os.environ, env, clear=True):
|
|
1049
|
+
config_filename = "mock_certificate_config.json"
|
|
1050
|
+
config_file_content = json.dumps(config_data)
|
|
1051
|
+
m = mock.mock_open(read_data=config_file_content)
|
|
1052
|
+
with mock.patch("builtins.open", m):
|
|
1053
|
+
with mock.patch.dict(
|
|
1054
|
+
os.environ, {"GOOGLE_API_CERTIFICATE_CONFIG": config_filename}
|
|
1055
|
+
):
|
|
1056
|
+
mock_api_endpoint = "foo"
|
|
1057
|
+
options = client_options.ClientOptions(
|
|
1058
|
+
client_cert_source=mock_client_cert_source,
|
|
1059
|
+
api_endpoint=mock_api_endpoint,
|
|
1060
|
+
)
|
|
1061
|
+
(
|
|
1062
|
+
api_endpoint,
|
|
1063
|
+
cert_source,
|
|
1064
|
+
) = client_class.get_mtls_endpoint_and_cert_source(options)
|
|
1065
|
+
assert api_endpoint == mock_api_endpoint
|
|
1066
|
+
assert cert_source is expected_cert_source
|
|
1067
|
+
|
|
860
1068
|
# Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never".
|
|
861
1069
|
with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
|
|
862
1070
|
api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source()
|
|
@@ -907,18 +1115,6 @@ def test_secure_source_manager_client_get_mtls_endpoint_and_cert_source(client_c
|
|
|
907
1115
|
== "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
|
|
908
1116
|
)
|
|
909
1117
|
|
|
910
|
-
# Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
|
|
911
|
-
with mock.patch.dict(
|
|
912
|
-
os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
|
|
913
|
-
):
|
|
914
|
-
with pytest.raises(ValueError) as excinfo:
|
|
915
|
-
client_class.get_mtls_endpoint_and_cert_source()
|
|
916
|
-
|
|
917
|
-
assert (
|
|
918
|
-
str(excinfo.value)
|
|
919
|
-
== "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
|
|
920
|
-
)
|
|
921
|
-
|
|
922
1118
|
|
|
923
1119
|
@pytest.mark.parametrize(
|
|
924
1120
|
"client_class", [SecureSourceManagerClient, SecureSourceManagerAsyncClient]
|
|
@@ -44504,6 +44700,7 @@ def test_secure_source_manager_grpc_asyncio_transport_channel():
|
|
|
44504
44700
|
|
|
44505
44701
|
# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are
|
|
44506
44702
|
# removed from grpc/grpc_asyncio transport constructor.
|
|
44703
|
+
@pytest.mark.filterwarnings("ignore::FutureWarning")
|
|
44507
44704
|
@pytest.mark.parametrize(
|
|
44508
44705
|
"transport_class",
|
|
44509
44706
|
[
|
|
File without changes
|
{google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/MANIFEST.in
RENAMED
|
File without changes
|
{google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/README.rst
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{google_cloud_securesourcemanager-0.2.0 → google_cloud_securesourcemanager-0.3.0}/tests/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|