Skip to content

Commit

Permalink
Fix bug caused by different variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
reidsunderland committed May 21, 2024
1 parent d2c3422 commit 58d4e52
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions sarracenia/flowcb/authenticate/nasa_earthdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ def add_token_for_url(self, url):
# to check again on the next run. If it is expired, we should get a brand new token.
today = datetime.datetime.utcnow().strftime("%m/%d/%Y")
if self._token_expires and today == self._token_expires:
logger.info("the token ending with ...{self._token[-5:]} expires today ({self._token_expires})")
logger.info(f"the token ending with ...{self._token[-5:]} expires today ({self._token_expires})")
self._token = None
self._token_expires = None
else:
logger.debug(f"token is not expired. today = {today}, token expires on {self._token_expires}")

# Get a token from the NASA API, if there isn't one already
if not self._token:
Expand All @@ -111,7 +113,7 @@ def add_token_for_url(self, url):
try:
token_already_in_creds = (ok and details.bearer_token == self._token)
if token_already_in_creds:
logger.debug(f"Token for {url} already in credentials database")
logger.debug(f"Token ...{self._token[-5:]} for {url} already in credentials database")
except:
token_already_in_creds = False

Expand Down Expand Up @@ -141,9 +143,9 @@ def create_earthdata_token(self, auth: requests.auth.HTTPBasicAuth) -> bool:
# logger.debug(f"Here's the response: {resp_j}")

self._token = resp_j['access_token']
self._token_expiry = resp_j['expiration_date']
self._token_expires = resp_j['expiration_date']
logger.info(f"Successfully created new token! " +
f"Token ends with ...{self._token[-5:]} and expires on {self._token_expiry}")
f"Token ends with ...{self._token[-5:]} and expires on {self._token_expires}")
return True

except Exception as e:
Expand Down Expand Up @@ -186,9 +188,9 @@ def get_bearer_token(self) -> bool:

if len(resp_j) >= 1:
self._token = resp_j[0]['access_token']
self._token_expiry = resp_j[0]['expiration_date']
self._token_expires = resp_j[0]['expiration_date']
logger.info(f"There is/are {len(resp_j)} token(s) in {username}'s Earthdata account. " +
f"Using the token that ends with ...{self._token[-5:]} and expires on {self._token_expiry}")
f"Using the token that ends with ...{self._token[-5:]} and expires on {self._token_expires}")
return True
# Valid response, but no tokens in the account. Need to create one.
else:
Expand All @@ -200,4 +202,4 @@ def get_bearer_token(self) -> bool:
logger.debug("details:", exc_info=True)
return False



0 comments on commit 58d4e52

Please sign in to comment.