Skip to content

Commit

Permalink
Fix to also try cloud authentication method when method=None (#481)
Browse files Browse the repository at this point in the history
* raise exception for empty cache

* raise value error for invalid gcloud credentials
  • Loading branch information
noahgolmant authored Jun 23, 2022
1 parent 58323d2 commit 42aa3dd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion gcsfs/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ def _connect_google_default(self):
def _connect_cloud(self):
self.credentials = gauth.compute_engine.Credentials()

if not self.credentials.valid:
raise ValueError("Invalid gcloud credentials")

def _connect_cache(self):

if len(self.tokens) == 0:
raise ValueError("No cached tokens")

project, access = self.project, self.access
if (project, access) in self.tokens:
credentials = self.tokens[(project, access)]
Expand Down Expand Up @@ -220,12 +227,15 @@ def connect(self, method=None):
self.connect(method=meth)
logger.debug("Connected with method %s", meth)
break
except google.auth.exceptions.GoogleAuthError as e:
except (google.auth.exceptions.GoogleAuthError, ValueError) as e:
# GoogleAuthError is the base class for all authentication
# errors
logger.debug(
'Connection with method "%s" failed' % meth, exc_info=e
)
# Reset credentials if they were set but the authentication failed
# (reverts to 'anon' behavior)
self.credentials = None
else:
# Since the 'anon' connection method should always succeed,
# getting here means something has gone terribly wrong.
Expand Down

0 comments on commit 42aa3dd

Please sign in to comment.