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

Define user .netrc directory [Feature request] #480

Closed
Rapsodia86 opened this issue Mar 4, 2024 · 7 comments · Fixed by #808
Closed

Define user .netrc directory [Feature request] #480

Rapsodia86 opened this issue Mar 4, 2024 · 7 comments · Fixed by #808
Assignees
Labels
enhancement New feature or request

Comments

@Rapsodia86
Copy link

Hello!
I would like to suggest an option to provide a user-specific directory to *.netrc file.
Now, it automatically looks into "C:\User\USERNAME\.netrc" (if in Windows).
However, I do have that file stored in another location that I use for my other scripts, and I do not see a reason to have it duplicated and spread across the machine.
How about adding the option in login like:

  1. Looks into the default directory for the file: earthaccess.login(strategy="netrc")
  2. Looks into user-specified location: earthaccess.login(strategy="netrc", dir="DIRECTORY\SUBDIRECTORY\")

Thanks!

@jhkennedy
Copy link
Collaborator

jhkennedy commented Mar 4, 2024

@Rapsodia86 would setting an environment variable work for you? For example:

os.environ['NETRC'] = 'C:\some\path\to\netrc'

earthaccess.login(strategy="netrc")

Would pick up your custom netrc at 'some/path/to/netrc'.

That's only a three line change here, I think:
https://github.com/nsidc/earthaccess/blob/main/earthaccess/auth.py#L258

but plumbing in a new argument is a bit more work.


Edit: Looks like the NETRC environment variable is common, e.g.:

@mfisher87 mfisher87 added the enhancement New feature or request label Mar 4, 2024
@Rapsodia86
Copy link
Author

Yes,
I think that is a good solution. No need to reinvent the wheel.
There is a following question. If I set os.environ['NETRC_PATH'] in the script, but then for some reason I use earthaccess.login(strategy="interactive",persist=true) will it pick up the .netrc file from that new (custom) directory or it will create a new .netrc file in the default location?

Thanks again!

@jhkennedy
Copy link
Collaborator

@Rapsodia86 sounds good!

If I set os.environ['NETRC_PATH'] in the script, but then for some reason I use earthaccess.login(strategy="interactive",persist=true) will it pick up the .netrc file from that new (custom) directory or it will create a new .netrc file in the default location?

How would you like it to work? Either could be supported, but I'd lean toward if the NETRC/NETRC_PATH (whichever name we chose) variable is set, we would write/update the custom one when doing earthaccess.login(strategy="interactive",persist=true)

@Rapsodia86
Copy link
Author

Yes, I agree! The consistent usage of NETRC/NETRC_PATH will allow to avoid confusion! Great:)

@jhkennedy jhkennedy self-assigned this Mar 4, 2024
@mfisher87
Copy link
Collaborator

Excellent decision, folks ;)

@chuckwondo
Copy link
Collaborator

FYI, we should simply be using requests.utils.get_netrc_auth, which conveniently takes care of all of this for us. See https://github.com/psf/requests/blob/v2.32.3/src/requests/utils.py#L204.

@cboettig
Copy link

cboettig commented Sep 2, 2024

fwiw, in GDAL this path is called:

GDAL_HTTP_NETRC_FILE=<filename>: (GDAL >= 3.7.0) Sets the location of a .netrc file.

In libcurl it is CURLOPT_NETRC_FILE

chuckwondo added a commit to chuckwondo/earthaccess that referenced this issue Sep 16, 2024
chuckwondo added a commit that referenced this issue Sep 16, 2024
Also, support `NETRC` environment variable for specifying
alternative location of `.netrc` file.

Fixes #806
Fixes #743
Fixes #480
chuckwondo added a commit to chuckwondo/earthaccess that referenced this issue Sep 17, 2024
chuckwondo added a commit to chuckwondo/earthaccess that referenced this issue Sep 22, 2024
chuckwondo added a commit to chuckwondo/earthaccess that referenced this issue Sep 24, 2024
chuckwondo added a commit to chuckwondo/earthaccess that referenced this issue Sep 26, 2024
@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in earthaccess project Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment