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

[BUG] earthaccess.login tries other strategies when it should not #945

Open
1 task done
chuckwondo opened this issue Feb 10, 2025 · 4 comments
Open
1 task done

Comments

@chuckwondo
Copy link
Collaborator

Is this issue already tracked somewhere, or is this a new report?

  • I've reviewed existing issues and couldn't find a duplicate for this problem.

Current Behavior

When calling earthaccess.login with a strategy other than "all", it might call one or more other strategies.

Expected Behavior

When calling earthaccess.login with a strategy other than "all", it should attempt only the specified strategy.

Steps To Reproduce

The following should ignore the env vars as well as netrc, and only prompt for creds, but does not.

It uses the env vars to login, even though the strategy is "interactive", not "all" (of course, replace username and password with valid Earthdata Login creds):

EARTHDATA_USERNAME=username EARTHDATA_PASSWORD=password python -c 'import earthaccess; earthaccess.login("interactive")'

If the creds are valid, you are not prompted for creds, as the env vars are used to successfully login, and thus the "interactive" strategy is skipped.

Conversely, if you use invalid creds for the env vars, login will still attempt to use them, but since login will fail with them, the "netrc" strategy will be tried. If you have a valid netrc entry, login will succeed without prompting you for creds.

Only when neither valid env vars nor a valid netrc entry exists will you will be prompted to enter creds. However, neither of the other strategies should be attempted at all, not even if a user enters invalid creds interactively.

Environment

- OS: macOS 15.3
- Python: 3.10.15

Additional Context

No response

@mfisher87
Copy link
Collaborator

mfisher87 commented Feb 10, 2025

There's the problem:

for strategy in ["environment", "netrc"]:

This is pretty magical! There are two places we are trying multiple strategies: one in api.py and again in __init__.py. Seems like we should only have one place that does this.

@mfisher87
Copy link
Collaborator

Perhaps the "all strategy" logic should be moved into the Auth class and out of both __init__.py and api.py.

@chuckwondo
Copy link
Collaborator Author

There's the problem:

earthaccess/earthaccess/init.py

Line 89 in 3f8b03a

for strategy in ["environment", "netrc"]:
This is pretty magical! There are two places we are trying multiple strategies: one in api.py and again in __init__.py. Seems like we should only have one place that does this.

Yep, we should not be doing that.

@mfisher87
Copy link
Collaborator

Yeah, to me it makes the most sense for this to all be encapsulated in the Auth class. We've got "spooky action" as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants