Skip to content

Commit

Permalink
Step1 on libraries import
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-smith committed May 12, 2024
1 parent 946ffb6 commit 8726a1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WORKDIR /code

# Configure locales
RUN apt update && \
apt install -y gettext locales && \
apt install -y gettext locales libyaml-cpp-dev && \
apt clean && \
rm -rf /var/lib/apt/lists/* && \
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
Expand Down
7 changes: 5 additions & 2 deletions backend/library/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from django.http import Http404

import yaml

# interesting thread: https://stackoverflow.com/questions/27743711/can-i-speedup-yaml
from ciso_assistant import settings
from core.models import (
Framework,
Expand Down Expand Up @@ -74,7 +76,7 @@ def get_available_libraries():
libs = AVAILABLE_LIBRARIES.get((fname, modified_time))
if libs is None:
with open(fname, "r", encoding="utf-8") as file:
libs = list(yaml.safe_load_all(file))
libs = list(yaml.load_all(file, Loader=yaml.CSafeLoader))
AVAILABLE_LIBRARIES[(fname, os.path.getmtime(fname))] = libs
for _lib in libs:
if (lib := Library.objects.filter(urn=_lib["urn"]).first()) is not None:
Expand Down Expand Up @@ -152,7 +154,8 @@ def get_library(urn: str) -> dict | None:
# Attempt to directly load the library from its specific YAML file.
if os.path.isfile(path):
with open(path, "r", encoding="utf-8") as file:
library_data = yaml.safe_load(file)
library_data = yaml.load(file, Loader=yaml.CSafeLoader)
# TODO: looks like we are going through here twice, why?
if library_data and library_data.get("urn") == urn:
return library_data
logger.error("File not found", path=path)
Expand Down

0 comments on commit 8726a1f

Please sign in to comment.