authentik.blueprints.management.commands.apply_blueprint
Apply blueprint from commandline
1"""Apply blueprint from commandline""" 2 3from argparse import ArgumentParser 4from sys import exit as sys_exit 5 6from django.core.management.base import BaseCommand, no_translations 7from structlog.stdlib import get_logger 8 9from authentik.blueprints.models import BlueprintInstance 10from authentik.blueprints.v1.importer import Importer 11from authentik.tenants.models import Tenant 12 13LOGGER = get_logger() 14 15 16class Command(BaseCommand): 17 """Apply blueprint from commandline""" 18 19 @no_translations 20 def handle(self, *args, **options): 21 """Apply all blueprints in order, abort when one fails to import""" 22 for tenant in Tenant.objects.filter(ready=True): 23 with tenant: 24 for blueprint_path in options.get("blueprints", []): 25 content = BlueprintInstance(path=blueprint_path).retrieve() 26 importer = Importer.from_string(content) 27 valid, logs = importer.validate() 28 if not valid: 29 self.stderr.write("Blueprint invalid") 30 for log in logs: 31 self.stderr.write(f"\t{log.logger}: {log.event}: {log.attributes}") 32 sys_exit(1) 33 importer.apply() 34 35 def add_arguments(self, parser: ArgumentParser): 36 parser.add_argument("blueprints", nargs="+", type=str)
LOGGER =
<BoundLoggerLazyProxy(logger=None, wrapper_class=None, processors=None, context_class=None, initial_values={}, logger_factory_args=())>
class
Command(django.core.management.base.BaseCommand):
17class Command(BaseCommand): 18 """Apply blueprint from commandline""" 19 20 @no_translations 21 def handle(self, *args, **options): 22 """Apply all blueprints in order, abort when one fails to import""" 23 for tenant in Tenant.objects.filter(ready=True): 24 with tenant: 25 for blueprint_path in options.get("blueprints", []): 26 content = BlueprintInstance(path=blueprint_path).retrieve() 27 importer = Importer.from_string(content) 28 valid, logs = importer.validate() 29 if not valid: 30 self.stderr.write("Blueprint invalid") 31 for log in logs: 32 self.stderr.write(f"\t{log.logger}: {log.event}: {log.attributes}") 33 sys_exit(1) 34 importer.apply() 35 36 def add_arguments(self, parser: ArgumentParser): 37 parser.add_argument("blueprints", nargs="+", type=str)
Apply blueprint from commandline
def
handle(*args, **kwargs):
106 def wrapper(*args, **kwargs): 107 from django.utils import translation 108 109 saved_locale = translation.get_language() 110 translation.deactivate_all() 111 try: 112 res = handle_func(*args, **kwargs) 113 finally: 114 if saved_locale is not None: 115 translation.activate(saved_locale) 116 return res
The type of the None singleton.