Skip to content

Commit

Permalink
Merge pull request #492 from nsidc/add_dodsrc_and_urs_cookies
Browse files Browse the repository at this point in the history
Add dodsrc and urs cookies files when creating netrc
  • Loading branch information
battistowx committed Mar 28, 2024
2 parents a86f959 + ccb4915 commit ff0c59a
Showing 1 changed file with 19 additions and 0 deletions.
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 @@ -369,6 +371,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

0 comments on commit ff0c59a

Please sign in to comment.