Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion gcsfs/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ def connect(self, method=None):
]:
self._connect_token(method)
elif method is None:
for meth in ["google_default", "cache", "cloud", "anon"]:
methods = ["google_default", "cache", "cloud", "anon"]
if os.environ.get("NO_GCE_CHECK") == "true":
methods.remove("cloud")
for meth in methods:
try:
self.connect(method=meth)
logger.debug("Connected with method %s", meth)
Expand Down
14 changes: 14 additions & 0 deletions gcsfs/tests/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ def test_googlecredentials_none():
credentials.apply(headers)


def test_no_gce_check_skips_cloud():
"""When NO_GCE_CHECK=true, the 'cloud' method should not be attempted."""
with patch.dict(os.environ, {"NO_GCE_CHECK": "true"}):
with patch.object(GoogleCredentials, "_connect_cloud") as mock_cloud:
# google_default and cloud will fail; anon will succeed
with patch.object(
GoogleCredentials,
"_connect_google_default",
side_effect=ValueError("no default"),
):
GoogleCredentials(project="myproject", token=None, access="read_only")
mock_cloud.assert_not_called()


def test_connect_google_default_uses_request():
with patch("gcsfs.credentials.gauth.default") as mock_default:
mock_default.return_value = (Mock(), "my-project")
Expand Down
Loading