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

Add dodsrc and urs cookies files when creating netrc #492

Merged
merged 10 commits into from
Mar 28, 2024
16 changes: 16 additions & 0 deletions earthaccess/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import importlib.metadata
import logging
import os
import platform
import shutil
from netrc import NetrcParseError
from pathlib import Path
from typing import Any, Dict, List, Optional
Expand Down Expand Up @@ -370,6 +372,20 @@ def _persist_user_credentials(self, username: str, password: str) -> bool:
my_netrc = Netrc(str(netrc_path))
my_netrc["urs.earthdata.nasa.gov"] = {"login": username, "password": password}
my_netrc.save()
netrc_file = Path.home() / ".netrc"
battistowx marked this conversation as resolved.
Show resolved Hide resolved

# Create and write .urs_cookies file
urs_cookies_file = Path.home() / ".urs_cookies"
urs_cookies_file.write_text("")

# Create and write to .dodsrc file
dodsrc_file = Path.home() / ".dodsrc"
dodsrc_contents = f"HTTP.COOKIEJAR={urs_cookies_file}\nHTTP.NETRC={netrc_file}"
battistowx marked this conversation as resolved.
Show resolved Hide resolved
dodsrc_file.write_text(dodsrc_contents)

if platform.system() == "Windows":
shutil.copy2(dodsrc_file, Path.cwd())

return True

def _get_cloud_auth_url(
Expand Down
Loading