Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug caused by different variable names #1060

Merged
merged 1 commit into from
May 21, 2024
Merged
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
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



Loading