From 72b56a86e10d53acb40efbc230ab0dfac5420d32 Mon Sep 17 00:00:00 2001 From: Corentin Forler Date: Thu, 14 Nov 2024 14:14:55 +0100 Subject: [PATCH] fix(s3): Use correct credentials to delete files --- press/press/doctype/remote_file/remote_file.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/press/press/doctype/remote_file/remote_file.py b/press/press/doctype/remote_file/remote_file.py index 5066548a31..f9f9862546 100644 --- a/press/press/doctype/remote_file/remote_file.py +++ b/press/press/doctype/remote_file/remote_file.py @@ -43,6 +43,7 @@ def poll_file_statuses(): "region": default_region, "access_key_id": aws_access_key, "secret_access_key": aws_secret_key, + "endpoint_url": press_settings.offsite_backups_endpoint, }, { "name": press_settings.remote_uploads_bucket, @@ -276,19 +277,27 @@ def delete_s3_files(buckets): if bucket_name == press_settings.aws_s3_bucket: endpoint_url = press_settings.offsite_backups_endpoint region_name = press_settings.backup_region + aws_access_key_id = press_settings.aws_access_key_id + aws_secret_access_key = press_settings.aws_secret_access_key elif bucket_name == press_settings.remote_uploads_bucket: endpoint_url = press_settings.remote_uploads_endpoint region_name = press_settings.remote_uploads_region + 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 + ) else: endpoint_url = frappe.db.get_value("Backup Bucket", bucket_name, "endpoint_url") region_name = frappe.db.get_value("Backup Bucket", bucket_name, "region") + 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 + ) 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 - ), + aws_access_key_id=aws_access_key_id, + aws_secret_access_key=aws_secret_access_key, region_name=region_name or "ap-south-1", endpoint_url=endpoint_url or "https://s3.amazonaws.com", )