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
19 changes: 19 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,23 @@ 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()
urs_cookies_path = Path.home() / ".urs_cookies"
if not urs_cookies_path.exists():
urs_cookies_path.write_text("")

# Create and write to .dodsrc file
dodsrc_path = Path.home() / ".dodsrc"
if not dodsrc_path.exists():
dodsrc_contents = (
f"HTTP.COOKIEJAR={urs_cookies_path}\nHTTP.NETRC={netrc_path}"
)
dodsrc_path.write_text(dodsrc_contents)

if platform.system() == "Windows":
local_dodsrc_path = Path.cwd() / dodsrc_path.name
if not local_dodsrc_path.exists():
shutil.copy2(dodsrc_path, local_dodsrc_path)

return True

def _get_cloud_auth_url(
Expand Down
Loading