From 97c09254495674afd1cf182da042259c7478f89a Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:37:56 +0000 Subject: [PATCH 01/10] Add .dodsrc and .urs_cookies files --- earthaccess/auth.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index 2a820402..58ed9bc6 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -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 @@ -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' + + # 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}" + dodsrc_file.write_text(dodsrc_contents) + + if platform.system() == "Windows": + shutil.copy2(dodsrc_file, Path.cwd()) + return True def _get_cloud_auth_url( From 080ccb4877ca94a18e14dfdb798309cf8c49d168 Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Thu, 14 Mar 2024 19:13:41 +0000 Subject: [PATCH 02/10] Change quotations --- earthaccess/auth.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index 58ed9bc6..d146cb48 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -372,14 +372,14 @@ 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' + netrc_file = Path.home() / ".netrc" # Create and write .urs_cookies file - urs_cookies_file = Path.home() / '.urs_cookies' - urs_cookies_file.write_text('') + urs_cookies_file = Path.home() / ".urs_cookies" + urs_cookies_file.write_text("") # Create and write to .dodsrc file - dodsrc_file = Path.home() / '.dodsrc' + dodsrc_file = Path.home() / ".dodsrc" dodsrc_contents = f"HTTP.COOKIEJAR={urs_cookies_file}\nHTTP.NETRC={netrc_file}" dodsrc_file.write_text(dodsrc_contents) From 28dad95589f2e415759f0fe1007600d21137c506 Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:28:43 -0400 Subject: [PATCH 03/10] Update earthaccess/auth.py Co-authored-by: Joseph H Kennedy --- earthaccess/auth.py | 1 - 1 file changed, 1 deletion(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index d146cb48..d7b928ad 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -372,7 +372,6 @@ 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" # Create and write .urs_cookies file urs_cookies_file = Path.home() / ".urs_cookies" From 467cf36e9a1aca346d3729f949d20dd5eb3f86ab Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Mon, 18 Mar 2024 14:28:54 -0400 Subject: [PATCH 04/10] Update earthaccess/auth.py Co-authored-by: Joseph H Kennedy --- earthaccess/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index d7b928ad..eff230f3 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -379,7 +379,7 @@ def _persist_user_credentials(self, username: str, password: str) -> bool: # Create and write to .dodsrc file dodsrc_file = Path.home() / ".dodsrc" - dodsrc_contents = f"HTTP.COOKIEJAR={urs_cookies_file}\nHTTP.NETRC={netrc_file}" + dodsrc_contents = f"HTTP.COOKIEJAR={urs_cookies_file}\nHTTP.NETRC={netrc_path}" dodsrc_file.write_text(dodsrc_contents) if platform.system() == "Windows": From dcb2adb7f1a89d1c880631f32f40f364ab3014d3 Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:45:06 -0400 Subject: [PATCH 05/10] Update earthaccess/auth.py Co-authored-by: Joseph H Kennedy --- earthaccess/auth.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index eff230f3..8e89cbdc 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -372,18 +372,22 @@ 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() - - # Create and write .urs_cookies file - urs_cookies_file = Path.home() / ".urs_cookies" - urs_cookies_file.write_text("") + urs_cookies_path = Path.home() / ".urs_cookies" + if not usr_cookies_path.exists(): + urs_cookies_path.write_text("") # Create and write to .dodsrc file - dodsrc_file = Path.home() / ".dodsrc" - dodsrc_contents = f"HTTP.COOKIEJAR={urs_cookies_file}\nHTTP.NETRC={netrc_path}" - dodsrc_file.write_text(dodsrc_contents) - - if platform.system() == "Windows": - shutil.copy2(dodsrc_file, Path.cwd()) + dodsrc_path = Path.home() / ".dodsrc" + if not dodsrc_path.exists(): + dodsrc_contents = f"HTTP.COOKIEJAR={urs_cookies_file}\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 From 0f74dac0cf89e712172ef0964b683cc14dfc054d Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:42:02 -0500 Subject: [PATCH 06/10] Fix indents and typo --- earthaccess/auth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index 8e89cbdc..bd7924f7 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -373,7 +373,7 @@ def _persist_user_credentials(self, username: str, password: str) -> bool: my_netrc["urs.earthdata.nasa.gov"] = {"login": username, "password": password} my_netrc.save() urs_cookies_path = Path.home() / ".urs_cookies" - if not usr_cookies_path.exists(): + if not urs_cookies_path.exists(): urs_cookies_path.write_text("") # Create and write to .dodsrc file @@ -383,7 +383,7 @@ def _persist_user_credentials(self, username: str, password: str) -> bool: dodsrc_path.write_text(dodsrc_contents) - if platform.system() == "Windows": + 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) From c251ca6cd1338ce3b88925f2a9b89d6dd724a880 Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:43:30 -0500 Subject: [PATCH 07/10] Change "file" to "path" --- earthaccess/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index bd7924f7..50b85e24 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -379,7 +379,7 @@ def _persist_user_credentials(self, username: str, password: str) -> bool: # Create and write to .dodsrc file dodsrc_path = Path.home() / ".dodsrc" if not dodsrc_path.exists(): - dodsrc_contents = f"HTTP.COOKIEJAR={urs_cookies_file}\nHTTP.NETRC={netrc_path}" + dodsrc_contents = f"HTTP.COOKIEJAR={urs_cookies_path}\nHTTP.NETRC={netrc_path}" dodsrc_path.write_text(dodsrc_contents) From 9e767bb69336719eac06e002fa8c28c1ba463ca5 Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:49:54 -0500 Subject: [PATCH 08/10] Fix formatting --- earthaccess/auth.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index 50b85e24..3f1cba28 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -379,16 +379,16 @@ def _persist_user_credentials(self, username: str, password: str) -> bool: # 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_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( From f4c90f671cabd541de43f6cf0f721a7e85cdcd03 Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:57:18 -0500 Subject: [PATCH 09/10] Fix whitespace formatting --- earthaccess/auth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index 3f1cba28..3797bbc5 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -383,12 +383,12 @@ def _persist_user_credentials(self, username: str, password: str) -> bool: 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( From ccb4915f3dfc0de730d2a32157cca657d4bebb30 Mon Sep 17 00:00:00 2001 From: Chris Battisto <34325676+battistowx@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:58:25 -0500 Subject: [PATCH 10/10] Fix extra whitespace --- earthaccess/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index 3797bbc5..d8d201f4 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -388,7 +388,7 @@ def _persist_user_credentials(self, username: str, password: str) -> bool: 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(