Add and document reencrypt_fields command
This commit is contained in:
parent
899bffb974
commit
4e603246f7
5 changed files with 41 additions and 0 deletions
0
src/servala/core/management/__init__.py
Normal file
0
src/servala/core/management/__init__.py
Normal file
0
src/servala/core/management/commands/__init__.py
Normal file
0
src/servala/core/management/commands/__init__.py
Normal file
21
src/servala/core/management/commands/reencrypt_fields.py
Normal file
21
src/servala/core/management/commands/reencrypt_fields.py
Normal 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")
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue