Skip to content

Commit

Permalink
Send auth instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbourbeau committed Aug 7, 2023
1 parent 4387ab6 commit d86e470
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 1 addition & 3 deletions earthaccess/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def download(
def open(
granules: Union[List[str], List[earthaccess.results.DataGranule]],
provider: Optional[str] = None,
store: Optional[Store] = None,
) -> List[AbstractFileSystem]:
"""Returns a list of fsspec file-like objects that can be used to access files
hosted on S3 or HTTPS by third party libraries like xarray.
Expand All @@ -187,8 +186,7 @@ def open(
Returns:
a list of s3fs "file pointers" to s3 files.
"""
store = store or earthaccess.__store__
results = store.open(granules=granules, provider=provider)
results = earthaccess.__store__.open(granules=granules, provider=provider)
return results


Expand Down
18 changes: 13 additions & 5 deletions earthaccess/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .daac import DAAC_TEST_URLS, find_provider
from .results import DataGranule
from .search import DataCollections
from .auth import Auth


class EarthAccessFile(fsspec.spec.AbstractBufferedFile):
Expand All @@ -33,8 +34,8 @@ def __getattr__(self, method: str) -> Any:
def __reduce__(self) -> Any:
return make_instance, (
type(self.f),
self.f,
earthaccess.__store__,
self.granule,
earthaccess.__auth__,
self.f.__reduce__(),
)

Expand Down Expand Up @@ -63,12 +64,19 @@ def multi_thread_open(data: tuple) -> EarthAccessFile:
return fileset


def make_instance(cls: Any, granule: DataGranule, store, _reduce: Any) -> EarthAccessFile:
if store.running_in_aws and cls is not s3fs.S3File:
def make_instance(
cls: Any, granule: DataGranule, auth: Auth, _reduce: Any
) -> EarthAccessFile:
# Attempt to re-authenticate
if not earthaccess.__auth__.authenticated:
earthaccess.__auth__ = auth
earthaccess.login()

if earthaccess.__store__.running_in_aws and cls is not s3fs.S3File:
# On AWS but not using a S3File. Reopen the file in this case for direct S3 access.
# NOTE: This uses the first data_link listed in the granule. That's not
# guaranteed to be the right one.
return EarthAccessFile(earthaccess.open([granule], store=store)[0], granule)
return EarthAccessFile(earthaccess.open([granule])[0], granule)
else:
func = _reduce[0]
args = _reduce[1]
Expand Down

0 comments on commit d86e470

Please sign in to comment.