diff --git a/program/management/commands/initialize.py b/program/management/commands/initialize.py new file mode 100644 index 0000000000000000000000000000000000000000..9067fe4c2bf0dd60d07e3a405587b107f0db591a --- /dev/null +++ b/program/management/commands/initialize.py @@ -0,0 +1,62 @@ +import os + +from django.core.management import call_command +from django.core.management.base import BaseCommand, CommandError + + +class Command(BaseCommand): + help = "Initializes the application." + + def handle(self, *args, **options): + AURA_PROTO = os.getenv("AURA_PROTO") + AURA_HOST = os.getenv("AURA_HOST") + + TANK_CALLBACK_BASE_URL = os.getenv( + "TANK_CALLBACK_BASE_URL", + default=f"{AURA_PROTO}://{AURA_HOST}/tank", + ) + DASHBOARD_CALLBACK_BASE_URL = os.getenv( + "DASHBOARD_CALLBACK_BASE_URL", + default=f"{AURA_PROTO}://${AURA_HOST}", + ) + + call_command("migrate", "--no-input") + + try: + call_command("createsuperuser", "--no-input") + except CommandError: + raise CommandError(f"The application is already initialized.") + + call_command("collectstatic", "--no-input") + call_command( + "create_oidc_client", + "dashboard", + "public", + "--client-id", + os.getenv("DASHBOARD_OIDC_CLIENT_ID"), + "--client-secret", + os.getenv("DASHBOARD_OIDC_CLIENT_SECRET"), + "-r", + "id_token token", + "-u", + f"{DASHBOARD_CALLBACK_BASE_URL}/oidc_callback.html", + "-u", + f"{DASHBOARD_CALLBACK_BASE_URL}/oidc_callback_silentRenew.html", + "-p", + DASHBOARD_CALLBACK_BASE_URL, + ) + call_command( + "create_oidc_client", + "tank", + "confidential", + "--client-id", + os.getenv("TANK_OIDC_CLIENT_ID"), + "--client-secret", + os.getenv("TANK_OIDC_CLIENT_SECRET"), + "-r", + "code", + "-u", + f"{TANK_CALLBACK_BASE_URL}/tank/auth/oidc/callback", + ) + call_command("addpermissions") + call_command("creatersakey") diff --git a/program/management/commands/loadfixtures.py b/program/management/commands/loadfixtures.py new file mode 100644 index 0000000000000000000000000000000000000000..354be2832378046ba0101c7faa456c360ed6f97b --- /dev/null +++ b/program/management/commands/loadfixtures.py @@ -0,0 +1,17 @@ +import glob + +from django.core.management import BaseCommand, call_command + + +class Command(BaseCommand): + help = "Loads the fixtures from the directory." + + def add_arguments(self, parser): + parser.add_argument("directory", help="Directory with fixtures.", nargs="+", type=str) + + def handle(self, *args, **options): + directories = options["directory"] + + for directory in directories: + if files := glob.glob(f"fixtures/{directory}/*.json"): + call_command("loaddata", files)