authentik.blueprints.management.commands.apply_blueprint
Apply blueprint from commandline
1"""Apply blueprint from commandline""" 2 3from sys import exit as sys_exit 4 5from django.core.management.base import BaseCommand, no_translations 6from structlog.stdlib import get_logger 7 8from authentik.blueprints.models import BlueprintInstance 9from authentik.blueprints.v1.importer import Importer 10from authentik.tenants.models import Tenant 11 12LOGGER = get_logger() 13 14 15class Command(BaseCommand): 16 """Apply blueprint from commandline""" 17 18 @no_translations 19 def handle(self, *args, **options): 20 """Apply all blueprints in order, abort when one fails to import""" 21 for tenant in Tenant.objects.filter(ready=True): 22 with tenant: 23 for blueprint_path in options.get("blueprints", []): 24 content = BlueprintInstance(path=blueprint_path).retrieve() 25 importer = Importer.from_string(content) 26 valid, logs = importer.validate() 27 if not valid: 28 self.stderr.write("Blueprint invalid") 29 for log in logs: 30 self.stderr.write(f"\t{log.logger}: {log.event}: {log.attributes}") 31 sys_exit(1) 32 importer.apply() 33 34 def add_arguments(self, parser): 35 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):
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): 36 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.