Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

earthaccess should start using CMR metadata to obtain S3 credentials #280

Closed
betolink opened this issue Aug 15, 2023 · 5 comments
Closed

Comments

@betolink
Copy link
Member

earthaccess uses a hard-coded list of DAAC endpoints to get temporary S3 credentials, however more and more datasets are under different endpoints and/or a different category( e.g. as services), Having earthaccess using the DirectDistributionInformation/S3CredentialsAPIEndpoint from the UMM metadata record would be a more robust solution. This could bring a time penalty so caching would also be nice to have.

@scottstanie
Copy link

I was going to make a discussion item about this, but I see this has already been opened.

I was trying to access this ASF product directly on S3: s3://asf-cumulus-prod-opera-products/OPERA_L2_CSLC-S1_T048-101101-IW3_20231102T232838Z_20231209T045008Z_S1A_VV_v1.0/OPERA_L2_CSLC-S1_T048-101101-IW3_20231102T232838Z_20231209T045008Z_S1A_VV_v1.0.h5 but using earthaccess.get_s3_credentials('ASF') uses the credential URL for Sentinel-1 ASF data instead of the correct one https://cumulus.asf.alaska.edu/s3credentials .

But while poking around, I see that you already added the ability to get the right credentials if you pass in the result:

In [9]: results = earthaccess.search_data(granule_name='OPERA_L2_CSLC-S1_T012-024520-IW1_20231007T124805Z_20231009T193746Z_S1A_VV_v1.0', concept_id="C2777443834-ASF")
Granules found: 1
In [10]: earthaccess.get_s3_credentials(results=results)
# this works!

I just wanted to check- is this the recommended way to get the login? Or is there some other way planned where you can request a different credentials URL before searching for results?

@jhkennedy
Copy link
Collaborator

jhkennedy commented Jan 16, 2024

@scottstanie thanks! Yes, ASF has multiple endpoints now and the best place to determine which endpoint to use is the CMR metadata.

@betolink do you think we could eliminate the hard coding entirely?

@scottstanie
Copy link

Thank you!
Also I realized right after I posted that, I can also use the search_datasets results to get credentials without picking a random product:

In [43]: rs = earthaccess.search_datasets(daac='ASF', keyword="OPERA_L2_CSLC-S1_V1")
Datasets found: 1

In [44]: rs[0].s3_bucket()
Out[44]:
{'Region': 'us-west-2',
 'S3BucketAndObjectPrefixNames': ['asf-cumulus-prod-opera-products/OPERA_L2_CSLC-S1/',
  'asf-cumulus-prod-opera-browse/OPERA_L2_CSLC-S1/'],
 'S3CredentialsAPIEndpoint': 'https://cumulus.asf.alaska.edu/s3credentials',
 'S3CredentialsAPIDocumentationURL': 'https://cumulus.asf.alaska.edu/s3credentialsREADME'}

but I noticed that I have to do

auth = earthaccess.login()
auth.get_s3_credentials(endpoint=...)

since the top level earthaccess.get_s3_credentials doesn't have the endpoint argument. Still seems easy enough for me though 👍

@betolink
Copy link
Member Author

I think this was resolved in v0.8.2

I tested this and it worked as expected without the need to specify the endpoint (it will use the metadata from CMR):

import earthaccess
import xarray as xr

earthaccess.login()

results = earthaccess.search_data(granule_name='OPERA_L2_CSLC-S1_T012-024520-IW1_20231007T124805Z_20231009T193746Z_S1A_VV_v1.0', concept_id="C2777443834-ASF")
file = earthaccess.open(results)[0]

ds = xr.open_dataset(file, group="data")
ds

if we want to download the file it would be the same:

import earthaccess

earthaccess.login()

results = earthaccess.search_data(granule_name='OPERA_L2_CSLC-S1_T012-024520-IW1_20231007T124805Z_20231009T193746Z_S1A_VV_v1.0', concept_id="C2777443834-ASF")
files = earthaccess.download(results, "opera/")

@asteiker
Copy link
Member

Resolved by #296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants