From aa12651f115e27a9aca38d88fa9fdb8d079c03ec Mon Sep 17 00:00:00 2001 From: Corentin Forler Date: Thu, 17 Oct 2024 17:46:07 +0200 Subject: [PATCH] refactor: Add enpoint_url param for offsite backups --- press/agent.py | 1 + .../press/doctype/site_backup/site_backup.py | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/press/agent.py b/press/agent.py index 4fcfe0c3d79..f584fef535c 100644 --- a/press/agent.py +++ b/press/agent.py @@ -459,6 +459,7 @@ def backup_site(self, site, with_files=False, offsite=False): "ACCESS_KEY": settings.offsite_backups_access_key_id, "SECRET_KEY": settings.get_password("offsite_backups_secret_access_key"), "REGION": backup_bucket.get("region") if isinstance(backup_bucket, dict) else "", + "ENDPOINT_URL": backup_bucket.get("endpoint_url") if isinstance(backup_bucket, dict) else "", } data.update( {"offsite": {"bucket": bucket_name, "auth": auth, "path": backups_path}} diff --git a/press/press/doctype/site_backup/site_backup.py b/press/press/doctype/site_backup/site_backup.py index 9777443a7f1..96f22838e03 100644 --- a/press/press/doctype/site_backup/site_backup.py +++ b/press/press/doctype/site_backup/site_backup.py @@ -13,6 +13,8 @@ from press.agent import Agent +from press.press.doctype.press_settings.press_settings import PressSettings + class SiteBackup(Document): # begin: auto-generated types @@ -212,14 +214,22 @@ def process_backup_site_job_update(job): def get_backup_bucket(cluster, region=False): bucket_for_cluster = frappe.get_all( - "Backup Bucket", {"cluster": cluster}, ["name", "region"], limit=1 + "Backup Bucket", {"cluster": cluster}, ["name", "region", "endpoint_url"], limit=1 ) - default_bucket = frappe.db.get_single_value("Press Settings", "aws_s3_bucket") + + if not bucket_for_cluster: + press_settings: "PressSettings" = frappe.get_single("Press Settings") # type: ignore + bucket_for_cluster = [ + { + "name": press_settings.aws_s3_bucket, + "region": press_settings.backup_region, + "endpoint_url": press_settings.offsite_backups_endpoint, + } + ] if region: - return bucket_for_cluster[0] if bucket_for_cluster else default_bucket - else: - return bucket_for_cluster[0]["name"] if bucket_for_cluster else default_bucket + return bucket_for_cluster[0] + return bucket_for_cluster[0]["name"] def on_doctype_update():