Skip to content

Commit

Permalink
feat: disable backup accounts for unpaid services
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Nov 27, 2024
1 parent 1be6635 commit 278a83b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions weblate_web/hetzner.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ def create_storage_folder(


def generate_subaccount_data(
dirname: str, service: Service, customer: Customer
dirname: str, service: Service, customer: Customer, *, access: bool = True
) -> dict[str, str]:
# Remove not allowed characters
customer_name = re.sub(r"[^\w,.&-]+", " ", customer.name)
return {
"homedirectory": f"weblate/{dirname}",
"ssh": "1",
"external_reachability": "1",
"external_reachability": "1" if access else "0",
"comment": f"Weblate backup ({service.pk}) {customer_name}"[:50],
}

Expand Down
9 changes: 7 additions & 2 deletions weblate_web/management/commands/backups_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ def sync_data(self, backup_services: dict[str, Service]) -> set[str]:
service.save(update_fields=["backup_box", "backup_directory"])

# Sync Hetzner data
storage_data = generate_subaccount_data(dirname, service, customer)
if storage["subaccount"]["comment"] != storage_data["comment"]:
storage_data = generate_subaccount_data(
dirname, service, customer, access=service.has_paid_backup()
)
if any(
storage["subaccount"][field] != value
for field, value in storage_data.items()
):
username: str = storage["subaccount"]["username"]
self.stdout.write(
f"Updating Hetzner data for {username} for {service.pk} ({customer.name})"
Expand Down

0 comments on commit 278a83b

Please sign in to comment.