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

fix(plugins): AWS rio_env s3_endpoint #1504

Merged
merged 2 commits into from
Jan 31, 2025
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
23 changes: 13 additions & 10 deletions eodag/plugins/download/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,20 +835,23 @@ def get_rio_env(
:param auth_dict: Dictionary containing authentication keys
:returns: The rasterio environement variables
"""
if self.s3_session is not None:
if self.requester_pays:
return {"session": self.s3_session, "requester_pays": True}
else:
return {"session": self.s3_session}
rio_env_kwargs = {}
if endpoint_url := getattr(self.config, "s3_endpoint", None):
rio_env_kwargs["endpoint_url"] = endpoint_url.split("://")[-1]
rio_env_kwargs |= auth_dict

if self.s3_session is None:
_ = self.get_authenticated_objects(bucket_name, prefix, auth_dict)

_ = self.get_authenticated_objects(bucket_name, prefix, auth_dict)
if self.s3_session is not None:
if self.requester_pays:
return {"session": self.s3_session, "requester_pays": True}
else:
return {"session": self.s3_session}
rio_env_kwargs["requester_pays"] = True
return {
"session": self.s3_session,
**rio_env_kwargs,
}
else:
return {"aws_unsigned": True}
return {"aws_unsigned": True, **rio_env_kwargs}

def get_authenticated_objects(
self, bucket_name: str, prefix: str, auth_dict: S3SessionKwargs
Expand Down
2 changes: 1 addition & 1 deletion eodag/plugins/search/creodias_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _update_assets(product: EOProduct, config: PluginConfig, auth: AwsAuth):
except botocore.exceptions.ClientError as e:
if str(auth.config.auth_error_code) in str(e):
raise AuthenticationError(
f"Authentication failed on {config.base_uri} s3"
f"Authentication failed on {config.s3_endpoint} s3"
) from e
raise NotAvailableError(
f"assets for product {prefix} could not be found"
Expand Down
45 changes: 45 additions & 0 deletions tests/units/test_download_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,51 @@ def test_plugins_download_aws_no_matching_product_type(
with self.assertRaises(NoMatchingProductType):
plugin.download(self.product, outputs_prefix=self.output_dir)

@mock.patch(
"eodag.plugins.download.aws.AwsDownload.get_authenticated_objects",
autospec=True,
)
def test_plugins_download_aws_get_rio_env(
self,
mock_get_authenticated_objects: mock.Mock,
):
"""AwsDownload.get_rio_env() must return rio env dict"""

self.product.properties["downloadLink"] = "s3://some-bucket/some/prefix"

plugin = self.get_download_plugin(self.product)
auth_plugin = self.get_auth_plugin(plugin, self.product)

# nothing needed
rio_env_dict = plugin.get_rio_env(
"some-bucket", "some/prefix", auth_plugin.authenticate()
)
self.assertDictEqual(rio_env_dict, {"aws_unsigned": True})

# s3_endpoint
plugin.config.s3_endpoint = "https://some.endpoint"
rio_env_dict = plugin.get_rio_env(
"some-bucket", "some/prefix", auth_plugin.authenticate()
)
self.assertDictEqual(
rio_env_dict, {"aws_unsigned": True, "endpoint_url": "some.endpoint"}
)

# session initiated
plugin.s3_session = mock.MagicMock()
self.assertEqual(plugin.config.requester_pays, True)
rio_env_dict = plugin.get_rio_env(
"some-bucket", "some/prefix", auth_plugin.authenticate()
)
self.assertDictEqual(
rio_env_dict,
{
"session": plugin.s3_session,
"endpoint_url": "some.endpoint",
"requester_pays": True,
},
)


class TestDownloadPluginS3Rest(BaseDownloadPluginTest):
def setUp(self):
Expand Down