Skip to content

Commit

Permalink
refactor(s3): Handle region and endpoints in delete_s3_files
Browse files Browse the repository at this point in the history
  • Loading branch information
cogk committed Oct 17, 2024
1 parent 557a036 commit 1d8590a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions press/press/doctype/remote_file/remote_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,26 @@ def delete_s3_files(buckets):

from press.utils import chunk

press_settings = frappe.get_single("Press Settings")
press_settings: "PressSettings" = frappe.get_single("Press Settings") # type: ignore
for bucket_name in buckets.keys():
if bucket_name == press_settings.aws_s3_bucket:
endpoint_url = press_settings.offsite_backups_endpoint
region_name = press_settings.backup_region
elif bucket_name == press_settings.remote_uploads_bucket:
endpoint_url = press_settings.remote_uploads_endpoint
region_name = press_settings.remote_uploads_region
else:
endpoint_url = frappe.db.get_value("Backup Bucket", bucket_name, "endpoint_url")
region_name = frappe.db.get_value("Backup Bucket", bucket_name, "region")

s3 = resource(
"s3",
aws_access_key_id=press_settings.offsite_backups_access_key_id,
aws_secret_access_key=press_settings.get_password(
"offsite_backups_secret_access_key", raise_exception=False
),
region_name=frappe.db.get_value("Backup Bucket", bucket_name, "region") or None,
endpoint_url=frappe.db.get_value("Backup Bucket", bucket_name, "endpoint_url")
or "https://s3.amazonaws.com",
region_name=region_name or "ap-south-1",
endpoint_url=endpoint_url or "https://s3.amazonaws.com",
)
bucket = s3.Bucket(bucket_name)
for objects in chunk([{"Key": x} for x in buckets[bucket_name]], 1000):
Expand Down

0 comments on commit 1d8590a

Please sign in to comment.