From 2af8ed9ad844b54a487beade185a16011c7b96f7 Mon Sep 17 00:00:00 2001 From: betolink Date: Tue, 21 Mar 2023 16:36:07 -0500 Subject: [PATCH 1/5] NSIDC implemented bearer tokens, now Auth will try both auth approaches to get the cloud credentials --- earthaccess/auth.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index 9e727221..6f54208d 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -140,7 +140,8 @@ def refresh_tokens(self) -> bool: def get_s3_credentials( self, daac: Optional[str] = "", provider: Optional[str] = "" ) -> Dict[str, str]: - """Gets AWS S3 credentials for a given NASA cloud provider + """Gets AWS S3 credentials for a given NASA cloud provider, the + easier way is to use the DAAC short name. provider is optional if we know it. Parameters: provider: A valid cloud provider, each DAAC has a provider code for their cloud distributions @@ -159,15 +160,26 @@ def get_s3_credentials( cumulus_resp.url, allow_redirects=True, timeout=15 ) if not (auth_resp.ok): # type: ignore - print( - f"Authentication with Earthdata Login failed with:\n{auth_resp.text[0:1000]}" + # Let's try to authenticate with Bearer tokens + session = self.get_session() + cumulus_resp = session.get( + auth_url, timeout=15, allow_redirects=True ) - eula_url = "https://urs.earthdata.nasa.gov/users/earthaccess/unaccepted_eulas" - apps_url = "https://urs.earthdata.nasa.gov/application_search" - print( - f"Consider accepting the EULAs available at {eula_url} and applications at {apps_url}" + auth_resp = session.get( + cumulus_resp.url, allow_redirects=True, timeout=15 ) - return {} + if not (auth_resp.ok): + print( + f"Authentication with Earthdata Login failed with:\n{auth_resp.text[0:1000]}" + ) + eula_url = "https://urs.earthdata.nasa.gov/users/earthaccess/unaccepted_eulas" + apps_url = "https://urs.earthdata.nasa.gov/application_search" + print( + f"Consider accepting the EULAs available at {eula_url} and applications at {apps_url}" + ) + return {} + + return auth_resp.json() return auth_resp.json() else: # This happens if the cloud provider doesn't list the S3 credentials or the DAAC From e381b66dabf4b935c3c212b2f521399879777441 Mon Sep 17 00:00:00 2001 From: betolink Date: Tue, 21 Mar 2023 17:01:31 -0500 Subject: [PATCH 2/5] fix mypy --- earthaccess/auth.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index 6f54208d..cf0cd971 100644 --- a/earthaccess/auth.py +++ b/earthaccess/auth.py @@ -161,11 +161,11 @@ def get_s3_credentials( ) if not (auth_resp.ok): # type: ignore # Let's try to authenticate with Bearer tokens - session = self.get_session() - cumulus_resp = session.get( + _session = self.get_session() + cumulus_resp = _session.get( auth_url, timeout=15, allow_redirects=True ) - auth_resp = session.get( + auth_resp = _session.get( cumulus_resp.url, allow_redirects=True, timeout=15 ) if not (auth_resp.ok): From b3bc46d5431dacda4552657ce3b5e9e77933414e Mon Sep 17 00:00:00 2001 From: betolink Date: Tue, 18 Apr 2023 18:14:04 -0500 Subject: [PATCH 3/5] version update --- earthaccess/api.py | 7 +++++-- pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/earthaccess/api.py b/earthaccess/api.py index 71d367ad..6813b9aa 100644 --- a/earthaccess/api.py +++ b/earthaccess/api.py @@ -7,7 +7,8 @@ import earthaccess from .auth import Auth -from .search import CollectionQuery, DataCollections, DataGranules, GranuleQuery +from .search import (CollectionQuery, DataCollections, DataGranules, + GranuleQuery) from .store import Store from .utils import _validation as validate @@ -196,7 +197,9 @@ def get_s3_credentials( Returns: a dictionary with S3 credentials for the DAAC or provider """ - return earthaccess.__auth__.get_s3_credentials(daac=daac, provider=provider) + return earthaccess.__auth__.get_s3_credentials( + daac=daac.upper(), provider=provider.upper() + ) def collection_query() -> Type[CollectionQuery]: diff --git a/pyproject.toml b/pyproject.toml index b185b1c4..82cc80fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "earthaccess" -version = "0.5.1" +version = "0.5.2" homepage = "https://github.com/nsidc/earthaccess" description = "Client library for NASA Earthdata APIs" authors = ["earthaccess contributors"] From 9fad4b123f44616cd561c2d1397682c22ee8f547 Mon Sep 17 00:00:00 2001 From: betolink Date: Thu, 20 Apr 2023 17:58:51 -0500 Subject: [PATCH 4/5] update changelog --- CHANGELOG.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 437c7620..ee42c5d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog -## Unreleased +## [v0.5.2] 2023-04-21 +* bug fixes: + * Fixing #230 by removing Benedict as the dict handler, thanks to @psarka! + * S3 credential endpoints are tried woth tokens and basic auth until all the DAACs accept the same auth + +* Core dependencies: + * Removed Benedict as the default dict for JSON coming from CMR. ## [v0.5.1] 2023-03-20 @@ -96,7 +102,8 @@ - Add basic classes to interact with NASA CMR, EDL and cloud access. - Basic object formatting. -[Unreleased]: https://github.com/nsidc/earthaccess/compare/v0.5.1...HEAD +[Unreleased]: https://github.com/nsidc/earthaccess/compare/v0.5.2...HEAD +[v0.5.2]: https://github.com/nsidc/earthaccess/releases/tag/v0.5.2 [v0.5.1]: https://github.com/nsidc/earthaccess/releases/tag/v0.5.1 [v0.5.0]: https://github.com/nsidc/earthaccess/releases/tag/v0.4.0 [v0.4.7]: https://github.com/nsidc/earthaccess/releases/tag/v0.4.7 From e80d167e61216b037646a3b573e91dea4c2b4dc6 Mon Sep 17 00:00:00 2001 From: betolink Date: Thu, 20 Apr 2023 18:20:01 -0500 Subject: [PATCH 5/5] fix mypy --- earthaccess/api.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/earthaccess/api.py b/earthaccess/api.py index 6813b9aa..e12e6414 100644 --- a/earthaccess/api.py +++ b/earthaccess/api.py @@ -7,8 +7,7 @@ import earthaccess from .auth import Auth -from .search import (CollectionQuery, DataCollections, DataGranules, - GranuleQuery) +from .search import CollectionQuery, DataCollections, DataGranules, GranuleQuery from .store import Store from .utils import _validation as validate @@ -197,9 +196,11 @@ def get_s3_credentials( Returns: a dictionary with S3 credentials for the DAAC or provider """ - return earthaccess.__auth__.get_s3_credentials( - daac=daac.upper(), provider=provider.upper() - ) + if daac is not None: + daac = daac.upper() + if provider is not None: + provider = provider.upper() + return earthaccess.__auth__.get_s3_credentials(daac=daac, provider=provider) def collection_query() -> Type[CollectionQuery]: