Skip to content

Commit

Permalink
Merge pull request #318 from jrbourbeau/data-links-fixup
Browse files Browse the repository at this point in the history
Return S3 data links by default when in region
  • Loading branch information
jrbourbeau authored Oct 23, 2023
2 parents 6fbc4ae + 3bcb243 commit cfc61a9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 1 addition & 2 deletions earthaccess/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def data_links(
s3_links = self._filter_related_links("GET DATA VIA DIRECT ACCESS")
if in_region:
# we are in us-west-2
if self.cloud_hosted and access is None:
if self.cloud_hosted and access in (None, "direct"):
# this is a cloud collection and we didn't specify the access type
# default to S3 links
if len(s3_links) == 0 and len(https_links) > 0:
Expand All @@ -325,7 +325,6 @@ def data_links(
else:
# we are not in us-west-2, even cloud collections have HTTPS links
return https_links
return https_links

def dataviz_links(self) -> List[str]:
"""
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import earthaccess


def test_data_links():
granules = earthaccess.search_data(
short_name="SEA_SURFACE_HEIGHT_ALT_GRIDS_L4_2SATS_5DAY_6THDEG_V_JPL2205",
temporal=("2020", "2022"),
count=1,
)
g = granules[0]
# `access` specified
assert g.data_links(access="direct")[0].startswith("s3://")
assert g.data_links(access="external")[0].startswith("https://")
# `in_region` specified
assert g.data_links(in_region=True)[0].startswith("s3://")
assert g.data_links(in_region=False)[0].startswith("https://")
# When `access` and `in_region` are both specified, `access` takes priority
assert g.data_links(access="direct", in_region=True)[0].startswith("s3://")
assert g.data_links(access="direct", in_region=False)[0].startswith("s3://")
assert g.data_links(access="external", in_region=True)[0].startswith("https://")
assert g.data_links(access="external", in_region=False)[0].startswith("https://")

0 comments on commit cfc61a9

Please sign in to comment.