diff --git a/src/palace/manager/service/storage/s3.py b/src/palace/manager/service/storage/s3.py index 9d9a5b508..290fff066 100644 --- a/src/palace/manager/service/storage/s3.py +++ b/src/palace/manager/service/storage/s3.py @@ -245,7 +245,9 @@ def multipart_abort(self, key: str, upload_id: str) -> None: UploadId=upload_id, ) - def update_bucket_expiration_rule(self, prefix: str, expiration_in_days: int = 30): + def update_bucket_expiration_rule( + self, prefix: str, expiration_in_days: int = 30 + ) -> None: """ Update the expiration lifecycle policy rule if it exists and has changed. If it does not already exist, add one. @@ -253,11 +255,6 @@ def update_bucket_expiration_rule(self, prefix: str, expiration_in_days: int = 3 rule_name = f"expiration_on_{prefix}" bucket = self.bucket configuration = self.client.get_bucket_lifecycle_configuration(Bucket=bucket) - if not configuration: - configuration = {} - - if "Rules" not in configuration: - configuration["Rules"] = [] rules_list = configuration["Rules"] for rule in rules_list: @@ -292,15 +289,15 @@ def update_bucket_expiration_rule(self, prefix: str, expiration_in_days: int = 3 try: policy_status = self.client.put_bucket_lifecycle_configuration( - Bucket=bucket, LifecycleConfiguration=configuration + Bucket=bucket, LifecycleConfiguration={"Rules": rules_list} # type: ignore[typeddict-item] ) self.log.info( - f"Updated configuration for {bucket}: " + f"Updated bucket lifecycle configuration for {bucket}: " f"configuration={configuration}, " f"status = {policy_status}" ) except ClientError as e: self.log.error( - f"Unable to apply bucket policy to {self.bucket} . \nReason:{e}" + f"Unable to apply bucket lifecycle configuration for {self.bucket}. \nReason:{e}" ) diff --git a/tests/manager/service/storage/test_s3.py b/tests/manager/service/storage/test_s3.py index bb07f3be8..80497917a 100644 --- a/tests/manager/service/storage/test_s3.py +++ b/tests/manager/service/storage/test_s3.py @@ -247,9 +247,9 @@ def test_update_bucket_expiration_rule_not_previously_set( prefix = "prefix/" expiration_in_days = 10 - s3_service_fixture.mock_s3_client.get_bucket_lifecycle_configuration.return_value = ( - None - ) + s3_service_fixture.mock_s3_client.get_bucket_lifecycle_configuration.return_value = { + "Rules": [] + } service.update_bucket_expiration_rule( prefix=prefix, expiration_in_days=expiration_in_days )