Skip to content

Commit

Permalink
refactor: Add enpoint_url param for offsite backups
Browse files Browse the repository at this point in the history
  • Loading branch information
cogk committed Nov 14, 2024
1 parent dc3d9e5 commit 682f648
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions press/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,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}})

Expand Down
20 changes: 16 additions & 4 deletions press/press/doctype/site_backup/site_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

if TYPE_CHECKING:
from datetime import datetime
from press.press.doctype.press_settings.press_settings import PressSettings


class SiteBackup(Document):
Expand Down Expand Up @@ -208,12 +209,23 @@ 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)
default_bucket = frappe.db.get_single_value("Press Settings", "aws_s3_bucket")
bucket_for_cluster = frappe.get_all(
"Backup Bucket", {"cluster": cluster}, ["name", "region", "endpoint_url"], limit=1
)

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
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():
Expand Down

0 comments on commit 682f648

Please sign in to comment.