Skip to content

Commit

Permalink
Merge pull request #234 from nsidc/auth-improvements
Browse files Browse the repository at this point in the history
Auth improvements
  • Loading branch information
betolink authored Apr 20, 2023
2 parents 9105029 + e80d167 commit 618311d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions earthaccess/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
28 changes: 20 additions & 8 deletions earthaccess/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down

0 comments on commit 618311d

Please sign in to comment.