Skip to content

Commit

Permalink
simplify conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfromearth committed May 10, 2024
1 parent b81bc98 commit 5dc84ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions earthaccess/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ def _netrc(self) -> bool:
raise FileNotFoundError(f"No .netrc found in {Path.home()}") from err
except NetrcParseError as err:
raise NetrcParseError("Unable to parse .netrc") from err
if (creds := my_netrc[self.system.edl_hostname]) is not None:
username = creds["login"]
password = creds["password"]
else:
if (creds := my_netrc[self.system.edl_hostname]) is None:
return False

username = creds["login"]
password = creds["password"]
authenticated = self._get_credentials(username, password)
if authenticated:
logger.debug("Using .netrc file for EDL")
Expand Down
20 changes: 12 additions & 8 deletions earthaccess/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ def __init__(self, auth: Optional[Auth] = None, *args: Any, **kwargs: Any) -> No
"""
super().__init__(*args, **kwargs)

if auth and auth.authenticated:
self.session = (
# To search, we need the new bearer tokens from NASA Earthdata
self.session = auth.get_session(bearer_token=True)
auth.get_session(bearer_token=True)
if auth and auth.authenticated
else requests.session()
)

if auth:
self.mode(auth.system.cmr_base_url)
else:
self.session = requests.sessions.Session()

self._debug = False

Expand Down Expand Up @@ -452,13 +454,15 @@ class DataGranules(GranuleQuery):
def __init__(self, auth: Optional[Auth] = None, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)

if auth and auth.authenticated:
self.session = (
# To search, we need the new bearer tokens from NASA Earthdata
self.session = auth.get_session(bearer_token=True)
auth.get_session(bearer_token=True)
if auth and auth.authenticated
else requests.session()
)

if auth:
self.mode(auth.system.cmr_base_url)
else:
self.session = requests.sessions.Session()

self._debug = False

Expand Down

0 comments on commit 5dc84ea

Please sign in to comment.