Skip to content

Commit

Permalink
Extract type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisher87 committed Feb 10, 2025
1 parent 58efc88 commit 2571e10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 2 additions & 3 deletions earthaccess/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Any,
Dict,
List,
Literal,
Mapping,
Optional,
Union,
Expand All @@ -19,7 +18,7 @@
from earthaccess.exceptions import LoginStrategyUnavailable
from earthaccess.services import DataServices

from .auth import Auth
from .auth import Auth, LoginFailureBehavior
from .results import DataCollection, DataGranule
from .search import CollectionQuery, DataCollections, DataGranules, GranuleQuery
from .store import Store
Expand Down Expand Up @@ -175,7 +174,7 @@ def login(
strategy: str = "all",
persist: bool = False,
system: System = PROD,
on_failure: Literal["warn", "error"] = "warn",
on_failure: LoginFailureBehavior = "warn",
) -> Auth:
"""Authenticate with Earthdata login (https://urs.earthdata.nasa.gov/).
Expand Down
11 changes: 6 additions & 5 deletions earthaccess/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


logger = logging.getLogger(__name__)
LoginFailureBehavior = Literal["error", "warn"]


def netrc_path() -> Path:
Expand Down Expand Up @@ -101,7 +102,7 @@ def login(
persist: bool = False,
system: Optional[System] = None,
*,
on_failure: Literal["warn", "error"],
on_failure: LoginFailureBehavior,
) -> Any:
"""Authenticate with Earthdata login.
Expand Down Expand Up @@ -242,7 +243,7 @@ def _interactive(
self,
persist_credentials: bool = False,
*,
on_failure: Literal["warn", "error"] = "warn",
on_failure: LoginFailureBehavior = "warn",
) -> bool:
username = input("Enter your Earthdata Login username: ")
password = getpass.getpass(prompt="Enter your Earthdata password: ")
Expand All @@ -256,7 +257,7 @@ def _interactive(
def _netrc(
self,
*,
on_failure: Literal["warn", "error"],
on_failure: LoginFailureBehavior,
) -> bool:
netrc_loc = netrc_path()

Expand Down Expand Up @@ -295,7 +296,7 @@ def _netrc(
def _environment(
self,
*,
on_failure: Literal["warn", "error"],
on_failure: LoginFailureBehavior,
) -> bool:
username = os.getenv("EARTHDATA_USERNAME")
password = os.getenv("EARTHDATA_PASSWORD")
Expand All @@ -314,7 +315,7 @@ def _get_credentials(
username: Optional[str],
password: Optional[str],
*,
on_failure: Literal["warn", "error"],
on_failure: LoginFailureBehavior,
) -> bool:
if username is not None and password is not None:
token_resp = self._find_or_create_token(username, password)
Expand Down

0 comments on commit 2571e10

Please sign in to comment.