eodag 3.9.1__py3-none-any.whl → 3.10.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,9 +24,11 @@ import boto3
24
24
  from botocore.exceptions import ClientError, ProfileNotFound
25
25
  from botocore.handlers import disable_signing
26
26
 
27
+ from eodag.api.product._assets import Asset
27
28
  from eodag.plugins.authentication.base import Authentication
28
29
  from eodag.types import S3SessionKwargs
29
- from eodag.utils.exceptions import AuthenticationError
30
+ from eodag.utils import get_bucket_name_and_prefix
31
+ from eodag.utils.exceptions import AuthenticationError, EodagError
30
32
 
31
33
  if TYPE_CHECKING:
32
34
  from mypy_boto3_s3 import S3Client, S3ServiceResource
@@ -283,3 +285,36 @@ class AwsAuth(Authentication):
283
285
  "session": self.s3_session,
284
286
  **rio_env_kwargs,
285
287
  }
288
+
289
+ def presign_url(
290
+ self,
291
+ asset: Asset,
292
+ expires_in: int = 3600,
293
+ ) -> str:
294
+ """This method is used to presign a url to download an asset from S3.
295
+
296
+ :param asset: asset for which the url shall be presigned
297
+ :param expires_in: expiration time of the presigned url in seconds
298
+ :returns: presigned url
299
+ :raises: :class:`~eodag.utils.exceptions.EodagError`
300
+ :raises: :class:`NotImplementedError`
301
+ """
302
+ if not getattr(self.config, "support_presign_url", True):
303
+ raise NotImplementedError(
304
+ f"presign_url is not supported for provider {self.provider}"
305
+ )
306
+
307
+ s3_client = self.get_s3_client()
308
+ bucket, prefix = get_bucket_name_and_prefix(asset["href"])
309
+ try:
310
+ presigned_url = s3_client.generate_presigned_url(
311
+ "get_object",
312
+ Params={
313
+ "Bucket": bucket,
314
+ "Key": prefix,
315
+ },
316
+ ExpiresIn=expires_in,
317
+ )
318
+ return presigned_url
319
+ except ClientError:
320
+ raise EodagError(f"Couldn't get a presigned URL for '{asset}'.")
@@ -19,6 +19,7 @@ from __future__ import annotations
19
19
 
20
20
  from typing import TYPE_CHECKING, Any, Optional, Union
21
21
 
22
+ from eodag.api.product._assets import Asset
22
23
  from eodag.plugins.base import PluginTopic
23
24
  from eodag.utils.exceptions import MisconfiguredError
24
25
 
@@ -80,3 +81,19 @@ class Authentication(PluginTopic):
80
81
  Authenticates with s3 and retrieves the available objects
81
82
  """
82
83
  raise NotImplementedError
84
+
85
+ def presign_url(
86
+ self,
87
+ asset: Asset,
88
+ expires_in: int = 3600,
89
+ ) -> str:
90
+ """This method is used to presign a url to download an asset from S3.
91
+
92
+ :param asset: asset for which the url shall be presigned
93
+ :param expires_in: expiration time of the presigned url in seconds
94
+ :returns: presigned url
95
+ :raises: :class:`NotImplementedError`
96
+ """
97
+ raise NotImplementedError(
98
+ f"presign_url is not implemented for plugin {type(self).__name__}"
99
+ )
@@ -25,6 +25,7 @@ from typing import TYPE_CHECKING, Optional
25
25
  import requests
26
26
  from requests.auth import AuthBase
27
27
 
28
+ from eodag.api.product._assets import Asset
28
29
  from eodag.plugins.authentication.base import Authentication
29
30
  from eodag.utils import HTTP_REQ_TIMEOUT, USER_AGENT, deepcopy, format_dict_items
30
31
  from eodag.utils.exceptions import AuthenticationError, TimeOutError
@@ -143,3 +144,17 @@ class SASAuth(Authentication):
143
144
  ssl_verify=ssl_verify,
144
145
  matching_url=matching_url,
145
146
  )
147
+
148
+ def presign_url(
149
+ self,
150
+ asset: Asset,
151
+ expires_in: int = 3600,
152
+ ) -> str:
153
+ """This method is used to presign a url to download an asset.
154
+
155
+ :param asset: asset for which the url shall be presigned
156
+ :param expires_in: expiration time of the presigned url in seconds
157
+ :returns: presigned url
158
+ """
159
+ url = asset["href"]
160
+ return self.config.auth_uri.format(url=url)
@@ -15,12 +15,19 @@
15
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
+ from __future__ import annotations
19
+
18
20
  from typing import Optional
19
21
 
20
22
  from eodag import EOProduct
21
23
  from eodag.plugins.download.aws import AwsDownload
24
+ from eodag.utils import _deprecated
22
25
 
23
26
 
27
+ @_deprecated(
28
+ reason="Plugin that was used in creodias_s3 provider configuration, but not anymore",
29
+ version="3.10.0",
30
+ )
24
31
  class CreodiasS3Download(AwsDownload):
25
32
  """
26
33
  Download on creodias s3 from their VMs (extension of :class:`~eodag.plugins.download.aws.AwsDownload`)