From 972cdefc2e927eeb015695c5a7b5cd66bac84bdf Mon Sep 17 00:00:00 2001 From: Alan King Date: Tue, 8 Oct 2024 11:29:40 -0400 Subject: [PATCH] [#282] Add hard stop for DeleteMode usage with S3 buckets DeleteMode is not supported for S3 bucket syncs, so we need to stop the sync job if something other than DO_NOT_DELETE is provided in order to prevent a silent no-op. --- .../tasks/s3_bucket_tasks.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/irods_capability_automated_ingest/tasks/s3_bucket_tasks.py b/irods_capability_automated_ingest/tasks/s3_bucket_tasks.py index c274fcd..41b4ac9 100644 --- a/irods_capability_automated_ingest/tasks/s3_bucket_tasks.py +++ b/irods_capability_automated_ingest/tasks/s3_bucket_tasks.py @@ -1,4 +1,4 @@ -from .. import sync_logging +from .. import sync_logging, utils from ..celery import app, RestartTask from ..char_map_util import translate_path from ..custom_event_handler import custom_event_handler @@ -80,6 +80,8 @@ def s3_bucket_sync_path(self, meta): logger = sync_logging.get_sync_logger(logging_config) + event_handler = custom_event_handler(meta) + proxy_url = meta.get("s3_proxy_url") if proxy_url is None: httpClient = None @@ -113,6 +115,15 @@ def s3_bucket_sync_path(self, meta): meta["task"] = "s3_bucket_sync_dir" chunk = {} + # Check to see whether the provided operation and delete_mode are compatible. + delete_mode = event_handler.delete_mode() + logger.debug(f"delete_mode: {delete_mode}") + # TODO(#282): S3 bucket syncs do not support DeleteMode (yet) + if utils.DeleteMode.DO_NOT_DELETE != delete_mode: + raise RuntimeError( + f"S3 bucket syncs do not support DeleteMode [{delete_mode}]. Only DeleteMode.DO_NOT_DELETE is supported." + ) + path_list = meta["path"].lstrip("/").split("/", 1) bucket_name = path_list[0] if len(path_list) == 1: