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 diff --git a/earthaccess/api.py b/earthaccess/api.py index 71d367ad..e12e6414 100644 --- a/earthaccess/api.py +++ b/earthaccess/api.py @@ -196,6 +196,10 @@ def get_s3_credentials( Returns: a dictionary with S3 credentials for the DAAC or provider """ + 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) diff --git a/earthaccess/auth.py b/earthaccess/auth.py index 9e727221..cf0cd971 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 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"]