Source code for commands.initialize_notification_config
"""Management command to check for initializing the notifications configuration."""fromtypingimportAnyfromdjango.core.management.baseimportBaseCommandfromnotifications.modelsimport(NotificationConfig,WeakECCCurve,WeakSignatureAlgorithm,)
[docs]classCommand(BaseCommand):"""Management command to initialize NotificationConfig with default weak ECC curves and signature algorithms."""
[docs]help='Initializes default NotificationConfig with known weak ECC curves and signature algorithms.'
[docs]defhandle(self,*args:Any,**kwargs:dict[str,Any])->None:# noqa: ARG002"""Create or update NotificationConfig with default weak ECC curves and signature algorithms."""self.stdout.write('Seeding weak ECC curves...')ecc_instances=[]foroid,labelinWeakECCCurve.ECCCurveChoices.choices:ecc,created=WeakECCCurve.objects.get_or_create(oid=oid)ecc_instances.append(ecc)self.stdout.write(f"{'Created'ifcreatedelse'Found'} ECC curve: {label} ({oid})")self.stdout.write('Seeding weak signature algorithms...')sig_instances=[]foroid,labelinWeakSignatureAlgorithm.SignatureChoices.choices:sig,created=WeakSignatureAlgorithm.objects.get_or_create(oid=oid)sig_instances.append(sig)self.stdout.write(f"{'Created'ifcreatedelse'Found'} Signature algorithm: {label} ({oid})")# Set them in the NotificationConfigconfig,created=NotificationConfig.objects.get_or_create()config.weak_ecc_curves.set(ecc_instances)config.weak_signature_algorithms.set(sig_instances)config.save()self.stdout.write(self.style.SUCCESS('Notification configuration initialized successfully.'))