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 Oct 17, 2024
1 parent 1d8590a commit aa12651
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions press/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
20 changes: 15 additions & 5 deletions press/press/doctype/site_backup/site_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit aa12651

Please sign in to comment.