Skip to content

Commit

Permalink
Move stored library initialization in app.startup
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Apr 29, 2024
1 parent 0e4dd16 commit aaac73b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion backend/core/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import sys
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from ciso_assistant.settings import CISO_ASSISTANT_SUPERUSER_EMAIL
from ciso_assistant.settings import CISO_ASSISTANT_SUPERUSER_EMAIL, LIBRARIES_PATH
import os


READER_PERMISSIONS_LIST = [
"view_project",
"view_riskassessment",
Expand Down Expand Up @@ -360,6 +362,20 @@ class CoreConfig(AppConfig):
verbose_name = "Core"

def ready(self):
from .models import StoredLibrary

# avoid post_migrate handler if we are in the main, as it interferes with restore
print("startup handler: import libraries")
print(LIBRARIES_PATH)
for fname in os.listdir(LIBRARIES_PATH):
print(f"Importing {fname}")
fname = str(LIBRARIES_PATH / fname)
if fname.endswith(".yaml"):
error = StoredLibrary.store_library_file(fname)
if error is not None:
print(
f"[ERROR] Can't import libary file '{fname}' : {error}",
file=sys.stderr,
)
if not os.environ.get("RUN_MAIN"):
post_migrate.connect(startup, sender=self)

0 comments on commit aaac73b

Please sign in to comment.