rs_server_catalog/data_management/s3_manager.md
Module handling all operations on S3 bucket.
S3Manager
Helper for catalog S3 operations.
The catalog uses S3 checks during item publication, presigned URL generation for downloads, checksum enrichment, and cleanup after catalog mutations. Local catalog mode intentionally short-circuits most S3 interactions.
Source code in docs/rs-server/services/catalog/rs_server_catalog/data_management/s3_manager.py
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 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 | |
__init__(s3_credentials)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s3_credentials
|
S3Credentials
|
S3 credentials |
required |
Source code in docs/rs-server/services/catalog/rs_server_catalog/data_management/s3_manager.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
check_if_item_can_be_published(content)
Check if all assets of a given catalog item exist on S3 and are valid for publishing.
Iterates through each asset in the content["assets"] dictionary and verifies
the presence of the S3 key (or folder/prefix) using check_s3_key. Logs the
results and any errors encountered. Returns True only if all assets exist;
returns False if at least one asset is missing or cannot be verified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
dict
|
A catalog item dictionary containing asset information under the "assets" key. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if all assets exist on S3 and can be published, False otherwise. |
Notes
- Handles exceptions raised by
check_s3_keyand logs errors without stopping iteration. - For folder/prefix assets, the size returned is ignored (-1), but existence is still validated.
- Cheap local validation runs before parallel S3 checks so invalid payloads fail fast.
Source code in docs/rs-server/services/catalog/rs_server_catalog/data_management/s3_manager.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 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 | |
check_s3_key(item, asset_name, s3_key)
Check if the given S3 key exists and matches the expected path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
dict
|
The item from the catalog (if it does exist) containing the asset. |
required |
asset_name
|
str
|
The name of the asset to check. |
required |
s3_key
|
str
|
The S3 key path to check against. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the S3 key is valid and exists, otherwise False. |
NOTE |
int
|
Don't mind if we have RSPY_LOCAL_CATALOG_MODE set to ON (meaning self.s3_handler is None) |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If the s3_handler is not available, if S3 paths cannot be retrieved, if the S3 paths do not match, or if there is an error checking the key. |
Source code in docs/rs-server/services/catalog/rs_server_catalog/data_management/s3_manager.py
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 | |
clear_catalog_bucket(content)
Clear files referenced by a rejected catalog payload.
This is used when stac-fastapi returns an error after middleware already prepared/staged asset paths. The method best-effort deletes those files to avoid orphaned catalog-bucket objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
dict
|
Files to delete |
required |
Source code in docs/rs-server/services/catalog/rs_server_catalog/data_management/s3_manager.py
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 | |
delete_s3_files(s3_files_to_be_deleted)
async
Delete S3 files collected during catalog request processing.
Deletion happens after the catalog mutation succeeds. Failures are logged but do not roll back the catalog response, because a secondary object storage lifecycle can still clean up orphaned objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s3_files_to_be_deleted
|
list[str]
|
list of files to delete from the S3 bucket |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True is deletion was successful, False otherwise |
Source code in docs/rs-server/services/catalog/rs_server_catalog/data_management/s3_manager.py
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 | |
generate_presigned_url(content, path)
Generate a time-limited S3 download URL for a catalog asset.
The requested asset id is extracted from the download route. The returned URL is intended for an HTTP redirect and should not be logged because it contains temporary access credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
dict
|
STAC description of the item to generate an URL for |
required |
path
|
str
|
Current path to this object |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Presigned URL |
int |
int
|
HTTP return code |
Source code in docs/rs-server/services/catalog/rs_server_catalog/data_management/s3_manager.py
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 | |
update_assets_checksums(content)
Update each asset with checksum data returned by S3 GetObjectAttributes.
Missing checksum metadata is non-fatal: publication can continue because object presence was already checked separately.
Source code in docs/rs-server/services/catalog/rs_server_catalog/data_management/s3_manager.py
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 | |
update_stac_item_publication(content, request, request_ids, item)
Update a STAC item before it is forwarded to pgstac.
The method enforces create/update semantics, adds RS Server-required STAC extensions, stores ownership in properties, and rewrites the collection id to the internal owner-prefixed form used by pgstac.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
dict
|
The content to update. |
required |
request
|
Request
|
The HTTP request object. |
required |
request_ids
|
dict
|
IDs associated to the given request |
required |
item
|
dict
|
The item from the catalog (if exists) to update. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The updated item body. |
Source code in docs/rs-server/services/catalog/rs_server_catalog/data_management/s3_manager.py
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 | |