Skip to content

Commit

Permalink
Fix mypy.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Dec 10, 2024
1 parent 4fe3f83 commit bff73f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
15 changes: 6 additions & 9 deletions src/palace/manager/service/storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,19 +245,16 @@ 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.
"""
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:
Expand Down Expand Up @@ -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}"
)
6 changes: 3 additions & 3 deletions tests/manager/service/storage/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit bff73f3

Please sign in to comment.