Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions eodag/api/product/_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,10 @@ def get_storage_options(
raise AddressNotFound(f"{asset_key} not found in {self} assets") from e
headers = {**USER_AGENT}

if isinstance(auth, ServiceResource) and isinstance(
self.downloader_auth, AwsAuth
if (
isinstance(auth, ServiceResource)
and isinstance(self.downloader_auth, AwsAuth)
and url.startswith("s3://")
):
auth_kwargs: dict[str, Any] = dict()
# AwsAuth
Expand Down
52 changes: 46 additions & 6 deletions tests/units/test_eoproduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,47 @@ def test_get_storage_options_http_qs(self):
},
)

@mock.patch("eodag.api.product._product.ServiceResource", new=object)
def test_get_storage_options_http_url_does_not_use_s3_auth(self):
"""HTTP products must not receive AWS/S3 storage options."""
product = EOProduct(
self.provider, self.eoproduct_props, collection=self.collection
)
auth_plugin = AwsAuth(
"foo",
PluginConfig.from_mapping(
{
"type": "Authentication",
"s3_endpoint": "http://foo.bar",
"credentials": {
"aws_access_key_id": "foo",
"aws_secret_access_key": "bar",
"aws_session_token": "baz",
},
"requester_pays": True,
}
),
)
auth_plugin.s3_session = mock.MagicMock()
auth_plugin.s3_session.get_credentials.return_value = mock.Mock(
access_key="foo",
secret_key="bar",
token="baz",
)
auth_plugin.authenticate = mock.MagicMock(return_value=object())
product.register_downloader(Download("foo", PluginConfig()), auth_plugin)
self.assertDictEqual(
product.get_storage_options(),
{"path": self.download_url},
)

@mock.patch("eodag.api.product._product.ServiceResource", new=object)
def test_get_storage_options_s3_credentials_endpoint(self):
"""get_storage_options should be adapted to the provider config using s3 credentials and endpoint"""
product = EOProduct(
self.provider, self.eoproduct_props, collection=self.collection
self.provider,
{**self.eoproduct_props, "eodag:download_link": "s3://foo/bar"},
collection=self.collection,
)
auth_plugin = AwsAuth(
"foo",
Expand Down Expand Up @@ -912,7 +948,7 @@ def test_get_storage_options_s3_credentials_endpoint(self):
self.assertDictEqual(
product.get_storage_options(),
{
"path": self.download_url,
"path": "s3://foo/bar",
"key": "foo",
"secret": "bar",
"token": "baz",
Expand All @@ -925,7 +961,9 @@ def test_get_storage_options_s3_credentials_endpoint(self):
def test_get_storage_options_s3_credentials(self):
"""get_storage_options should be adapted to the provider config using s3 credentials"""
product = EOProduct(
self.provider, self.eoproduct_props, collection=self.collection
self.provider,
{**self.eoproduct_props, "eodag:download_link": "s3://foo/bar"},
collection=self.collection,
)
auth_plugin = AwsAuth(
"foo",
Expand All @@ -951,7 +989,7 @@ def test_get_storage_options_s3_credentials(self):
self.assertDictEqual(
product.get_storage_options(),
{
"path": self.download_url,
"path": "s3://foo/bar",
"key": "foo",
"secret": "bar",
"token": "baz",
Expand All @@ -962,7 +1000,9 @@ def test_get_storage_options_s3_credentials(self):
def test_get_storage_options_s3_anon(self):
"""get_storage_options should be adapted to the provider config using anonymous s3 access"""
product = EOProduct(
self.provider, self.eoproduct_props, collection=self.collection
self.provider,
{**self.eoproduct_props, "eodag:download_link": "s3://foo/bar"},
collection=self.collection,
)
auth_plugin = AwsAuth(
"foo",
Expand All @@ -977,7 +1017,7 @@ def test_get_storage_options_s3_anon(self):
self.assertDictEqual(
product.get_storage_options(),
{
"path": self.download_url,
"path": "s3://foo/bar",
"anon": True,
},
)
Expand Down
Loading