eodag 2.12.0__py3-none-any.whl → 3.0.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.
Files changed (93) hide show
  1. eodag/__init__.py +6 -8
  2. eodag/api/core.py +654 -538
  3. eodag/api/product/__init__.py +12 -2
  4. eodag/api/product/_assets.py +59 -16
  5. eodag/api/product/_product.py +100 -93
  6. eodag/api/product/drivers/__init__.py +7 -2
  7. eodag/api/product/drivers/base.py +0 -3
  8. eodag/api/product/metadata_mapping.py +192 -96
  9. eodag/api/search_result.py +69 -10
  10. eodag/cli.py +55 -25
  11. eodag/config.py +391 -116
  12. eodag/plugins/apis/base.py +11 -165
  13. eodag/plugins/apis/ecmwf.py +36 -25
  14. eodag/plugins/apis/usgs.py +80 -35
  15. eodag/plugins/authentication/aws_auth.py +13 -4
  16. eodag/plugins/authentication/base.py +10 -1
  17. eodag/plugins/authentication/generic.py +2 -2
  18. eodag/plugins/authentication/header.py +31 -6
  19. eodag/plugins/authentication/keycloak.py +17 -84
  20. eodag/plugins/authentication/oauth.py +3 -3
  21. eodag/plugins/authentication/openid_connect.py +268 -49
  22. eodag/plugins/authentication/qsauth.py +4 -1
  23. eodag/plugins/authentication/sas_auth.py +9 -2
  24. eodag/plugins/authentication/token.py +98 -47
  25. eodag/plugins/authentication/token_exchange.py +122 -0
  26. eodag/plugins/crunch/base.py +3 -1
  27. eodag/plugins/crunch/filter_date.py +3 -9
  28. eodag/plugins/crunch/filter_latest_intersect.py +0 -3
  29. eodag/plugins/crunch/filter_latest_tpl_name.py +1 -4
  30. eodag/plugins/crunch/filter_overlap.py +4 -8
  31. eodag/plugins/crunch/filter_property.py +5 -11
  32. eodag/plugins/download/aws.py +149 -185
  33. eodag/plugins/download/base.py +88 -97
  34. eodag/plugins/download/creodias_s3.py +1 -1
  35. eodag/plugins/download/http.py +638 -310
  36. eodag/plugins/download/s3rest.py +47 -45
  37. eodag/plugins/manager.py +228 -88
  38. eodag/plugins/search/__init__.py +36 -0
  39. eodag/plugins/search/base.py +239 -30
  40. eodag/plugins/search/build_search_result.py +382 -37
  41. eodag/plugins/search/cop_marine.py +441 -0
  42. eodag/plugins/search/creodias_s3.py +25 -20
  43. eodag/plugins/search/csw.py +5 -7
  44. eodag/plugins/search/data_request_search.py +61 -30
  45. eodag/plugins/search/qssearch.py +713 -255
  46. eodag/plugins/search/static_stac_search.py +106 -40
  47. eodag/resources/ext_product_types.json +1 -1
  48. eodag/resources/product_types.yml +1921 -34
  49. eodag/resources/providers.yml +4091 -3655
  50. eodag/resources/stac.yml +50 -216
  51. eodag/resources/stac_api.yml +71 -25
  52. eodag/resources/stac_provider.yml +5 -0
  53. eodag/resources/user_conf_template.yml +89 -32
  54. eodag/rest/__init__.py +6 -0
  55. eodag/rest/cache.py +70 -0
  56. eodag/rest/config.py +68 -0
  57. eodag/rest/constants.py +26 -0
  58. eodag/rest/core.py +735 -0
  59. eodag/rest/errors.py +178 -0
  60. eodag/rest/server.py +264 -431
  61. eodag/rest/stac.py +442 -836
  62. eodag/rest/types/collections_search.py +44 -0
  63. eodag/rest/types/eodag_search.py +238 -47
  64. eodag/rest/types/queryables.py +164 -0
  65. eodag/rest/types/stac_search.py +273 -0
  66. eodag/rest/utils/__init__.py +216 -0
  67. eodag/rest/utils/cql_evaluate.py +119 -0
  68. eodag/rest/utils/rfc3339.py +64 -0
  69. eodag/types/__init__.py +106 -10
  70. eodag/types/bbox.py +15 -14
  71. eodag/types/download_args.py +40 -0
  72. eodag/types/search_args.py +57 -7
  73. eodag/types/whoosh.py +79 -0
  74. eodag/utils/__init__.py +110 -91
  75. eodag/utils/constraints.py +37 -45
  76. eodag/utils/exceptions.py +39 -22
  77. eodag/utils/import_system.py +0 -4
  78. eodag/utils/logging.py +37 -80
  79. eodag/utils/notebook.py +4 -4
  80. eodag/utils/repr.py +113 -0
  81. eodag/utils/requests.py +128 -0
  82. eodag/utils/rest.py +100 -0
  83. eodag/utils/stac_reader.py +93 -21
  84. {eodag-2.12.0.dist-info → eodag-3.0.0.dist-info}/METADATA +88 -53
  85. eodag-3.0.0.dist-info/RECORD +109 -0
  86. {eodag-2.12.0.dist-info → eodag-3.0.0.dist-info}/WHEEL +1 -1
  87. {eodag-2.12.0.dist-info → eodag-3.0.0.dist-info}/entry_points.txt +7 -5
  88. eodag/plugins/apis/cds.py +0 -540
  89. eodag/rest/types/stac_queryables.py +0 -134
  90. eodag/rest/utils.py +0 -1133
  91. eodag-2.12.0.dist-info/RECORD +0 -94
  92. {eodag-2.12.0.dist-info → eodag-3.0.0.dist-info}/LICENSE +0 -0
  93. {eodag-2.12.0.dist-info → eodag-3.0.0.dist-info}/top_level.txt +0 -0
eodag/rest/errors.py ADDED
@@ -0,0 +1,178 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2024, CS GROUP - France, https://www.csgroup.eu/
3
+ #
4
+ # This file is part of EODAG project
5
+ # https://www.github.com/CS-SI/EODAG
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ import logging
19
+ from typing import Dict, List, Tuple, Union
20
+
21
+ from fastapi import FastAPI, Request
22
+ from fastapi.responses import ORJSONResponse
23
+ from starlette import status
24
+ from starlette.exceptions import HTTPException as StarletteHTTPException
25
+
26
+ from eodag.rest.types.eodag_search import EODAGSearch
27
+ from eodag.utils.exceptions import (
28
+ AuthenticationError,
29
+ DownloadError,
30
+ EodagError,
31
+ MisconfiguredError,
32
+ NoMatchingProductType,
33
+ NotAvailableError,
34
+ RequestError,
35
+ TimeOutError,
36
+ UnsupportedProductType,
37
+ UnsupportedProvider,
38
+ ValidationError,
39
+ )
40
+
41
+ EODAG_DEFAULT_STATUS_CODES = {
42
+ AuthenticationError: status.HTTP_500_INTERNAL_SERVER_ERROR,
43
+ DownloadError: status.HTTP_500_INTERNAL_SERVER_ERROR,
44
+ MisconfiguredError: status.HTTP_500_INTERNAL_SERVER_ERROR,
45
+ NotAvailableError: status.HTTP_404_NOT_FOUND,
46
+ NoMatchingProductType: status.HTTP_404_NOT_FOUND,
47
+ TimeOutError: status.HTTP_504_GATEWAY_TIMEOUT,
48
+ UnsupportedProductType: status.HTTP_404_NOT_FOUND,
49
+ UnsupportedProvider: status.HTTP_404_NOT_FOUND,
50
+ ValidationError: status.HTTP_400_BAD_REQUEST,
51
+ }
52
+
53
+ logger = logging.getLogger("eodag.rest.server")
54
+
55
+
56
+ class ResponseSearchError(Exception):
57
+ """Represent a EODAG search error response"""
58
+
59
+ def __init__(self, errors: List[Tuple[str, Exception]]) -> None:
60
+ self._errors = errors
61
+
62
+ @property
63
+ def errors(self) -> List[Dict[str, Union[str, int]]]:
64
+ """return errors as a list of dict"""
65
+ error_list: List[Dict[str, Union[str, int]]] = []
66
+ for name, exception in self._errors:
67
+
68
+ error_dict: Dict[str, Union[str, int]] = {
69
+ "provider": name,
70
+ "error": exception.__class__.__name__,
71
+ }
72
+
73
+ if exception.args:
74
+ error_dict["message"] = exception.args[0]
75
+
76
+ if len(exception.args) > 1:
77
+ error_dict["detail"] = " ".join([str(i) for i in exception.args[1:]])
78
+
79
+ error_dict["status_code"] = EODAG_DEFAULT_STATUS_CODES.get(
80
+ type(exception), getattr(exception, "status_code", 500)
81
+ )
82
+
83
+ if type(exception) in (MisconfiguredError, AuthenticationError):
84
+ logger.error("%s: %s", type(exception).__name__, str(exception))
85
+ error_dict[
86
+ "message"
87
+ ] = "Internal server error: please contact the administrator"
88
+ error_dict.pop("detail", None)
89
+
90
+ if type(exception) is ValidationError:
91
+ for error_param in exception.parameters:
92
+ stac_param = EODAGSearch.to_stac(error_param)
93
+ exception.message = exception.message.replace(
94
+ error_param, stac_param
95
+ )
96
+ error_dict["message"] = exception.message
97
+
98
+ error_list.append(error_dict)
99
+
100
+ return error_list
101
+
102
+ @property
103
+ def status_code(self) -> int:
104
+ """get global errors status code"""
105
+ if len(self._errors) == 1 and type(self.errors[0]["status_code"]) is int:
106
+ return self.errors[0]["status_code"]
107
+
108
+ return 400
109
+
110
+
111
+ async def response_search_error_handler(
112
+ request: Request, exc: Exception
113
+ ) -> ORJSONResponse:
114
+ """Handle ResponseSearchError exceptions"""
115
+ if not isinstance(exc, ResponseSearchError):
116
+ return starlette_exception_handler(request, exc)
117
+
118
+ return ORJSONResponse(
119
+ status_code=exc.status_code,
120
+ content={"errors": exc.errors},
121
+ )
122
+
123
+
124
+ async def eodag_errors_handler(request: Request, exc: Exception) -> ORJSONResponse:
125
+ """Handler for EODAG errors"""
126
+ if not isinstance(exc, EodagError):
127
+ return starlette_exception_handler(request, exc)
128
+
129
+ code = EODAG_DEFAULT_STATUS_CODES.get(type(exc), getattr(exc, "status_code", 500))
130
+ detail = f"{type(exc).__name__}: {str(exc)}"
131
+
132
+ if type(exc) in (MisconfiguredError, AuthenticationError, TimeOutError):
133
+ logger.error("%s: %s", type(exc).__name__, str(exc))
134
+
135
+ if type(exc) in (MisconfiguredError, AuthenticationError):
136
+ detail = "Internal server error: please contact the administrator"
137
+
138
+ if type(exc) is ValidationError:
139
+ for error_param in exc.parameters:
140
+ stac_param = EODAGSearch.to_stac(error_param)
141
+ exc.message = exc.message.replace(error_param, stac_param)
142
+ detail = exc.message
143
+
144
+ return ORJSONResponse(
145
+ status_code=code,
146
+ content={"description": detail},
147
+ )
148
+
149
+
150
+ def starlette_exception_handler(request: Request, error: Exception) -> ORJSONResponse:
151
+ """Default errors handle"""
152
+ description = (
153
+ getattr(error, "description", None)
154
+ or getattr(error, "detail", None)
155
+ or str(error)
156
+ )
157
+ return ORJSONResponse(
158
+ status_code=getattr(error, "status_code", 500),
159
+ content={"description": description},
160
+ )
161
+
162
+
163
+ def add_exception_handlers(app: FastAPI) -> None:
164
+ """Add exception handlers to the FastAPI application.
165
+
166
+ Args:
167
+ app: the FastAPI application.
168
+
169
+ Returns:
170
+ None
171
+ """
172
+ app.add_exception_handler(StarletteHTTPException, starlette_exception_handler)
173
+
174
+ app.add_exception_handler(RequestError, eodag_errors_handler)
175
+ for exc in EODAG_DEFAULT_STATUS_CODES:
176
+ app.add_exception_handler(exc, eodag_errors_handler)
177
+
178
+ app.add_exception_handler(ResponseSearchError, response_search_error_handler)