Common
Authentication functions implementation.
Note: calls https://gitlab.si.c-s.fr/space_applications/eoservices/apikey-manager
__apikey_security_cached(apikey_value)
async
Cached version of apikey_security. Cache an infinite (sys.maxsize) number of results for 120 seconds.
This function serves as a cached version of apikey_security. It retrieves user access control information from the User Authentication and Authorization Control (UAC) manager and caches the result for performance optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
apikey_value |
str
|
The API key value. |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple[list[str], dict, str]
|
A tuple containing user IAM roles, configuration data, and user login information. |
Raises:
Type | Description |
---|---|
HTTPException
|
If there is an error connecting to the UAC manager or if the UAC manager returns an error. |
Source code in docs/rs-server/services/common/rs_server_common/authentication.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
apikey_security(request, apikey_header)
async
FastAPI Security dependency for the cluster mode. Check the api key validity, passed as an HTTP header.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
apikey_header |
Security
|
API key passed in HTTP header |
required |
Returns:
Type | Description |
---|---|
tuple[list[str], dict, str]
|
Tuple of (IAM roles, config, user login) information from the keycloak account, associated to the api key. |
Source code in docs/rs-server/services/common/rs_server_common/authentication.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
apikey_validator(station, access_type)
Decorator to validate API key access for a specific station and access type.
This decorator checks if the authorization key contains the necessary role to access the specified station with the specified access type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
station |
str
|
The name of the station, either "adgs" or "cadip". |
required |
access_type |
str
|
The type of access, such as "download" or "read". |
required |
Raises:
Type | Description |
---|---|
HTTPException
|
If the authorization key does not include the required role to access the specified station with the specified access type. |
Returns:
Name | Type | Description |
---|---|---|
function |
Callable
|
The decorator function. |
Source code in docs/rs-server/services/common/rs_server_common/authentication.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
Database connection.
Taken from: https://praciano.com.br/fastapi-and-async-sqlalchemy-20-with-pytest-done-right.html
DatabaseSessionManager
Database session configuration.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
__filelock(func)
staticmethod
Avoid concurrent writing to the database using a file locK.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
__init__()
Create a Database session configuration.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
49 50 51 52 |
|
close()
Close database session.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
97 98 99 100 101 102 |
|
connect()
Open new database connection instance.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
create_all()
Create all database tables.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
160 161 162 163 164 |
|
drop_all()
Drop all database tables.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
166 167 168 169 170 |
|
open_session(url='')
Open database session.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
reraise_http_exception(exception)
classmethod
Re-raise all exceptions into HTTP exceptions.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
172 173 174 175 176 177 178 179 180 181 |
|
session()
Open new database session instance.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
url()
classmethod
Get database connection URL.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
get_db()
Return a database session for FastAPI dependency injection.
Source code in docs/rs-server/services/common/rs_server_common/db/database.py
187 188 189 190 191 192 193 194 195 |
|
Logging utility.
CustomFormatter
Bases: Formatter
Custom logging formatter with colored text. See: https://stackoverflow.com/a/56944256
Source code in docs/rs-server/services/common/rs_server_common/utils/logging.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
Logging
Logging utility.
Attributes:
Name | Type | Description |
---|---|---|
lock |
For code synchronization |
|
level |
Minimal log level to use for all new logging instances. |
Source code in docs/rs-server/services/common/rs_server_common/utils/logging.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
default(name='rspy')
classmethod
Return a default Logger class instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Logger name. You can pass name to use your current module name. |
'rspy'
|
Source code in docs/rs-server/services/common/rs_server_common/utils/logging.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
OpenTelemetry utility
init_traces(app, service_name)
Init instrumentation of OpenTelemetry traces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app |
FastAPI
|
FastAPI application |
required |
service_name |
str
|
service name |
required |
Source code in docs/rs-server/services/common/rs_server_common/utils/opentelemetry.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
This module is used to share common functions between apis endpoints
EoDAGDownloadHandler
dataclass
Dataclass to store arguments needed for eodag download.
Attributes:
Name | Type | Description |
---|---|---|
db_handler |
DownloadStatus
|
An instance used to access the database. |
thread_started |
Event
|
Event to signal the start of the download thread. |
station |
str
|
Station identifier (needed only for CADIP). |
product_id |
str
|
Identifier of the product to be downloaded. |
name |
str
|
Filename of the file to be downloaded. |
local |
str | None
|
Local path where the product will be stored |
obs |
str | None
|
Path to the S3 storage where the file will be uploaded |
Source code in docs/rs-server/services/common/rs_server_common/utils/utils.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
create_stac_collection(products, feature_template, stac_mapper)
Creates a STAC feature collection based on a given template for a list of EOProducts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
products |
List[EOProduct]
|
A list of EOProducts to create STAC features for. |
required |
feature_template |
dict
|
The template for generating STAC features. |
required |
stac_mapper |
dict
|
The mapping dictionary for converting EOProduct data to STAC properties. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The STAC feature collection containing features for each EOProduct. |
Source code in docs/rs-server/services/common/rs_server_common/utils/utils.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
eodag_download(argument, db, init_provider, **kwargs)
Initiates the eodag download process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
argument |
EoDAGDownloadHandler
|
An instance of EoDAGDownloadHandler containing the arguments used in the |
required |
downloading process. db: The database connection object. init_provider (Callable[[str], Provider]): A function to initialize the provider for downloading. **kwargs: Additional keyword arguments.
Note
The local and obs parameters are optional: - local (str | None): Local path where the product will be stored. If this parameter is not given, the local path where the file is stored will be set to a temporary one. - obs (str | None): Path to S3 storage where the file will be uploaded, after a successful download from CADIP server. If this parameter is not given, the file will not be uploaded to the S3 storage.
Raises:
Type | Description |
---|---|
RuntimeError
|
If there is an issue connecting to the S3 storage during the download. |
Source code in docs/rs-server/services/common/rs_server_common/utils/utils.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
extract_eo_product(eo_product, mapper)
This function is creating key:value pairs from an EOProduct properties
Source code in docs/rs-server/services/common/rs_server_common/utils/utils.py
377 378 379 |
|
is_valid_date_format(date)
Check if a string adheres to the expected date format "YYYY-MM-DDTHH:MM:SS.sssZ".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date |
str
|
The string to be validated for the specified date format. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the input string adheres to the expected date format, otherwise False. |
Source code in docs/rs-server/services/common/rs_server_common/utils/utils.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
odata_to_stac(feature_template, odata_dict, odata_stac_mapper)
Maps OData values to a given STAC template.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature_template |
dict
|
The STAC feature template to be populated. |
required |
odata_dict |
dict
|
The dictionary containing OData values. |
required |
odata_stac_mapper |
dict
|
The mapping dictionary for converting OData keys to STAC properties. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The populated STAC feature template. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided STAC feature template is invalid. |
Source code in docs/rs-server/services/common/rs_server_common/utils/utils.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
sort_feature_collection(feature_collection, sortby)
Sorts a STAC feature collection based on a given criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature_collection |
dict
|
The STAC feature collection to be sorted. |
required |
sortby |
str
|
The sorting criteria. Use "+fieldName" for ascending order or "-fieldName" for descending order. Use "+doNotSort" to skip sorting. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The sorted STAC feature collection. |
Note
If sortby is not in the format of "+fieldName" or "-fieldName", the function defaults to ascending order by the "datetime" field.
Source code in docs/rs-server/services/common/rs_server_common/utils/utils.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
update_db(db, db_product, estatus, status_fail_message=None)
Update the download status of a product in the database.
This function attempts to update the download status of a product in the database. It retries the update operation for a maximum of three times, waiting 1 second between attempts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db |
Session
|
The database session. |
required |
db_product |
DownloadStatus
|
The product whose status needs to be updated. |
required |
estatus |
EDownloadStatus
|
The new download status. |
required |
status_fail_message |
Optional[str]
|
An optional message associated with the failure status. |
None
|
Raises:
Type | Description |
---|---|
OperationalError(exc)
|
If the database update operation fails after multiple attempts. |
Example
update_db(db_session, product_instance, EDownloadStatus.DONE)
Note
- This function is designed to update the download status in the database.
- It retries the update operation for a maximum of three times.
- If the update fails, an exception is raised, indicating an issue with the database.
Source code in docs/rs-server/services/common/rs_server_common/utils/utils.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
validate_inputs_format(interval)
Validate the format of the input time interval.
This function checks whether the input interval has a valid format (start_date/stop_date) and whether the start and stop dates are in a valid ISO 8601 format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval |
str
|
The time interval to be validated, with the following format: "2024-01-01T00:00:00Z/2024-01-02T23:59:59Z" |
required |
Returns:
Type | Description |
---|---|
Union[None, datetime]
|
Tuple[Union[None, datetime], Union[None, datetime]]: A tuple containing: - start_date (datetime): The start date of the interval. - stop_date (datetime): The stop date of the interval. |
Union[None, datetime]
|
Or [None, None] if the provided interval is empty. |
Note
- The input interval should be in the format "start_date/stop_date" (e.g., "2022-01-01T00:00:00Z/2022-01-02T00:00:00Z").
- This function checks for missing start/stop and validates the ISO 8601 format of start and stop dates.
- If there is an error, err_code and err_text provide information about the issue.
Source code in docs/rs-server/services/common/rs_server_common/utils/utils.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
write_search_products_to_db(db_handler_class, products)
Processes a list of products by adding them to the database if not already present.
This function iterates over a list of products. For each product, it checks whether the product is already registered in the database. If the product is not in the database, it is added with its relevant details. The function collects a list of product IDs and names for further processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_handler_class |
DownloadStatus
|
The database handler class used for database operations. |
required |
products |
List[Product]
|
A list of product objects to be processed. |
required |
Returns:
Name | Type | Description |
---|---|---|
products |
List[Tuple[str, str]]
|
A list of tuples, each containing the 'id' and 'Name' properties of a product. |
Raises:
Type | Description |
---|---|
OperationalError
|
If there's an issue connecting to the database. |
Notes: The function assumes that 'products' is a list of objects with a 'properties' attribute, which is a dictionary containing keys 'id', 'Name', and 'startTimeFromAscendingNode'.
'get_db' is a context manager that provides a database session.
'EDownloadStatus' is an enumeration representing download status.
Source code in docs/rs-server/services/common/rs_server_common/utils/utils.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
EODAG Provider.
EodagProvider
Bases: Provider
An EODAG provider.
It uses EODAG to provide data from external sources.
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/eodag_provider.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
__del__()
Destructor
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/eodag_provider.py
52 53 54 55 56 57 |
|
__init__(config_file, provider)
Create a EODAG provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_file |
Path
|
the path to the eodag configuration file |
required |
provider |
str
|
the name of the eodag provider |
required |
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/eodag_provider.py
39 40 41 42 43 44 45 46 47 48 49 50 |
|
create_eodag_product(product_id, filename)
Initialize an EO product with minimal properties.
The title is used by EODAG as the name of the downloaded file. The download link is used by EODAG as http request url for download. The geometry is mandatory in an EO Product so we add the all earth as geometry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
product_id |
str
|
the id of EO Product |
required |
filename |
str
|
the name of the downloaded file |
required |
Returns:
Name | Type | Description |
---|---|---|
product |
EOProduct
|
the initialized EO Product |
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/eodag_provider.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
download(product_id, to_file)
Download the expected product at the given local location.
EODAG needs an EOProduct to download. We build an EOProduct from the id and download location to be able to call EODAG for download.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
product_id |
str
|
the id of the product to download |
required |
to_file |
Path
|
the path where the product has to be download |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/eodag_provider.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
init_eodag_client(config_file)
Initialize the eodag client.
The EODAG client is initialized for the given provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_file |
Path
|
the path to the eodag configuration file |
required |
Returns:
Type | Description |
---|---|
EODataAccessGateway
|
the initialized eodag client |
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/eodag_provider.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
Provider mechanism.
CreateProviderFailed
Bases: Exception
Exception raised when an error occurred during the init of a provider.
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/provider.py
53 54 |
|
DownloadProductFailed
Bases: Exception
Exception raised when an error occurred during the download.
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/provider.py
61 62 |
|
Product
dataclass
A product.
A product has an external identifier and a dictionary of metadata.
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/provider.py
42 43 44 45 46 47 48 49 50 |
|
Provider
Bases: ABC
A product provider.
A provider gives a common interface to search for files from an external data source and download them locally.
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/provider.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
download(product_id, to_file)
abstractmethod
Download the given product to the given local path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
product_id |
str
|
id of the product to download |
required |
to_file |
Path
|
path where the file should be downloaded |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/provider.py
105 106 107 108 109 110 111 112 113 114 115 116 |
|
search(between, **kwargs)
Search for products with the given time range.
The search result is a dictionary of products found indexed by id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
between |
TimeRange
|
the search period |
required |
Returns:
Type | Description |
---|---|
Any
|
The files found indexed by file id. Specific to each provider. |
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/provider.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
SearchProductFailed
Bases: Exception
Exception raised when an error occurred during the search.
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/provider.py
57 58 |
|
TimeRange
dataclass
A time range.
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/provider.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
duration()
Duration of the timerange.
Returns: duration of the timerange
Source code in docs/rs-server/services/common/rs_server_common/data_retrieval/provider.py
31 32 33 34 35 36 |
|
TODO Docstring to be added.
GetKeysFromS3Config
dataclass
S3 configuration for download
Attributes:
Name | Type | Description |
---|---|---|
s3_files |
list
|
A list with the S3 object keys to be downloaded. |
bucket |
str
|
The S3 bucket name. |
local_prefix |
str
|
The local prefix where files will be downloaded. |
overwrite |
bool
|
Flag indicating whether to overwrite existing files. Default is False. |
max_retries |
int
|
The maximum number of download retries. Default is DWN_S3FILE_RETRIES. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
PutFilesToS3Config
dataclass
Configuration for uploading files to S3.
Attributes:
Name | Type | Description |
---|---|---|
files |
List
|
A list with the local file paths to be uploaded. |
bucket |
str
|
The S3 bucket name. |
s3_path |
str
|
The S3 path where files will be uploaded. |
max_retries |
int
|
The maximum number of upload retries. Default is UP_S3FILE_RETRIES. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
S3StorageHandler
Interacts with an S3 storage
S3StorageHandler for interacting with an S3 storage service.
Attributes:
Name | Type | Description |
---|---|---|
access_key_id |
str
|
The access key ID for S3 authentication. |
secret_access_key |
str
|
The secret access key for S3 authentication. |
endpoint_url |
str
|
The endpoint URL for the S3 service. |
region_name |
str
|
The region name. |
s3_client |
client
|
The s3 client to interact with the s3 storage |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
|
__get_s3_client(access_key_id, secret_access_key, endpoint_url, region_name)
Retrieve or create an S3 client instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
access_key_id |
str
|
The access key ID for S3 authentication. |
required |
secret_access_key |
str
|
The secret access key for S3 authentication. |
required |
endpoint_url |
str
|
The endpoint URL for the S3 service. |
required |
region_name |
str
|
The region name. |
required |
Returns:
Name | Type | Description |
---|---|---|
client |
boto3
|
An S3 client instance. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
__init__(access_key_id, secret_access_key, endpoint_url, region_name)
Initialize the S3StorageHandler instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
access_key_id |
str
|
The access key ID for S3 authentication. |
required |
secret_access_key |
str
|
The secret access key for S3 authentication. |
required |
endpoint_url |
str
|
The endpoint URL for the S3 service. |
required |
region_name |
str
|
The region name. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the connection to the S3 storage cannot be established. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
check_bucket_access(bucket)
Check the accessibility of an S3 bucket.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket |
str
|
The S3 bucket name. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
If an error occurs during the bucket access check. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
|
check_file_overwriting(local_file, overwrite)
Check if file exists and determine if it should be overwritten.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_file |
str
|
Path to the local file. |
required |
overwrite |
bool
|
Whether to overwrite the existing file. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the file should be overwritten, False otherwise. |
Note: - If the file already exists and the overwrite flag is set to True, the function logs a message, deletes the existing file, and returns True. - If the file already exists and the overwrite flag is set to False, the function logs a warning message, and returns False. In this case, the existing file won't be deleted. - If the file doesn't exist, the function returns True.
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
|
connect_s3()
Establish a connection to the S3 service.
If the S3 client is not already instantiated, this method calls the private get_s3_client method to create an S3 client instance using the provided credentials and configuration (see __init).
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
delete_file_from_s3(bucket, s3_obj)
Delete a file from S3.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket |
str
|
The S3 bucket name. |
required |
s3_obj |
str
|
The S3 object key. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
If an error occurs during the bucket access check. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
disconnect_s3()
Close the connection to the S3 service.
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
181 182 183 184 185 186 |
|
files_to_be_downloaded(bucket, paths)
Create a list with the S3 keys to be downloaded.
The list will have the s3 keys to be downloaded from the bucket. It contains pairs (local_prefix_where_the_file_will_be_downloaded, full_s3_key_path) If a s3 key doesn't exist, the pair will be (None, requested_s3_key_path)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket |
str
|
The S3 bucket name. |
required |
paths |
list
|
List of S3 object keys. |
required |
Returns:
Name | Type | Description |
---|---|---|
list_with_files |
list
|
List of tuples (local_prefix, full_s3_key_path). |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
files_to_be_uploaded(paths)
Creates a list with the local files to be uploaded.
The list contains pairs (s3_path, absolute_local_file_path) If the local file doesn't exist, the pair will be (None, requested_file_to_upload)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths |
list
|
List of local file paths. |
required |
Returns:
Name | Type | Description |
---|---|---|
list_with_files |
list
|
List of tuples (s3_path, absolute_local_file_path). |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
get_basename(input_path)
staticmethod
Get the filename from a full path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_path |
str
|
The full path. |
required |
Returns:
Name | Type | Description |
---|---|---|
filename |
str
|
The filename. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
239 240 241 242 243 244 245 246 247 248 249 250 |
|
get_keys_from_s3(config)
Download S3 keys specified in the configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
GetKeysFromS3Config
|
Configuration for the S3 download. |
required |
Returns:
Type | Description |
---|---|
list
|
List[str]: A list with the S3 keys that couldn't be downloaded. |
Raises:
Type | Description |
---|---|
Exception
|
Any unexpected exception raised during the download process. |
The function attempts to download files from S3 according to the provided configuration. It returns a list of S3 keys that couldn't be downloaded successfully.
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
|
get_secrets_from_file(secrets, secret_file)
staticmethod
Read secrets from a specified file.
It reads the secrets from .s3cfg or aws credentials files This function should not be used in production
Parameters:
Name | Type | Description | Default |
---|---|---|---|
secrets |
dict
|
Dictionary to store retrieved secrets. |
required |
secret_file |
str
|
Path to the file containing secrets. |
required |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
list_s3_files_obj(bucket, prefix)
Retrieve the content of an S3 directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket |
str
|
The S3 bucket name. |
required |
prefix |
str
|
The S3 object key prefix. |
required |
Returns:
Name | Type | Description |
---|---|---|
s3_files |
list
|
List containing S3 object keys. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
put_files_to_s3(config)
Upload files to S3 according to the provided configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
PutFilesToS3Config
|
Configuration for the S3 upload. |
required |
Returns:
Type | Description |
---|---|
list
|
List[str]: A list with the local file paths that couldn't be uploaded. |
Raises:
Type | Description |
---|---|
Exception
|
Any unexpected exception raised during the upload process. |
The function attempts to upload files to S3 according to the provided configuration. It returns a list of local files that couldn't be uploaded successfully.
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
|
s3_path_parser(s3_url)
staticmethod
Parses S3 URL to extract bucket, prefix, and file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s3_url |
str
|
The S3 URL. |
required |
Returns:
Type | Description |
---|---|
bucket, prefix, s3_file) (tuple
|
Tuple containing bucket, prefix, and file. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
transfer_from_s3_to_s3(config)
Copy S3 keys specified in the configuration. Args: config (TransferFromS3ToS3Config): Configuration object containing bucket source, bucket destination, S3 files, maximum retries.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
A list of S3 keys that failed to be copied. |
Raises:
Type | Description |
---|---|
Exception
|
Any unexpected exception raised during the upload process. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
|
wait_timeout(timeout)
Wait for a specified timeout duration (minimum 200 ms).
This function implements a simple timeout mechanism, where it sleeps for 0.2 seconds in each iteration until the cumulative sleep time reaches the specified timeout duration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
float
|
The total duration to wait in seconds. |
required |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
TransferFromS3ToS3Config
dataclass
S3 configuration for copying a list with keys between buckets
Attributes:
Name | Type | Description |
---|---|---|
s3_files |
list
|
A list with the S3 object keys to be copied. |
bucket_src |
str
|
The source S3 bucket name. |
bucket_dst |
str
|
The destination S3 bucket name. |
max_retries |
int
|
The maximum number of download retries. Default is DWN_S3FILE_RETRIES. |
Source code in docs/rs-server/services/common/rs_server_common/s3_storage_handler/s3_storage_handler.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|