Add and document reencrypt_fields command

This commit is contained in:
Tobias Kunze 2025-03-21 15:58:52 +01:00
parent 899bffb974
commit 4e603246f7
5 changed files with 41 additions and 0 deletions

View file

View file

@ -0,0 +1,21 @@
from django.core.management.base import BaseCommand
from django.db import transaction
from servala.core.models.service import ControlPlane
class Command(BaseCommand):
help = "Re-encrypts all encrypted fields. Use when rotating SECRET_KEY/SALT"
def handle(self, *args, **options):
self.stdout.write("Starting re-encryption of ControlPlane objects...")
count = 0
with transaction.atomic():
for control_plane in ControlPlane.objects.all():
control_plane.save()
count += 1
self.stdout.write(
self.style.SUCCESS(f"Re-encrypted {count} ControlPlane objects")
)