Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 17, 2024
1 parent 3f06325 commit a0fb868
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions surfactant/infoextractors/js_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
# SPDX-License-Identifier: MIT
import json
import pathlib
import re
from typing import Any, Dict, List

Expand All @@ -12,11 +11,9 @@
from loguru import logger

import surfactant.plugin
from surfactant.configmanager import ConfigManager
from surfactant.sbomtypes import SBOM, Software

from surfactant.configmanager import ConfigManager
import os
from pathlib import Path

def supports_file(filetype) -> bool:
return filetype == "JAVASCRIPT"
Expand All @@ -31,7 +28,9 @@ def extract_file_info(sbom: SBOM, software: Software, filename: str, filetype: s

def extract_js_info(filename: str) -> object:
js_info: Dict[str, Any] = {"jsLibraries": []}
js_lib_file = ConfigManager().get_data_dir_path() / "infoextractors" / "js_library_patterns.json"
js_lib_file = (
ConfigManager().get_data_dir_path() / "infoextractors" / "js_library_patterns.json"
)

# Load expressions from retire.js, should move this file elsewhere
try:
Expand Down Expand Up @@ -123,7 +122,9 @@ def update_db():
cleaned = strip_irrelevant_data(retirejs)
path = ConfigManager().get_data_dir_path() / "infoextractors"
path.mkdir(parents=True, exist_ok=True)
json_file_path = ConfigManager().get_data_dir_path() / "infoextractors" / "js_library_patterns.json"
json_file_path = (
ConfigManager().get_data_dir_path() / "infoextractors" / "js_library_patterns.json"
)
with open(json_file_path, "w") as f:
json.dump(cleaned, f, indent=4)
return "Update complete."
Expand All @@ -134,18 +135,22 @@ def update_db():
def short_name():
return "js_file"


def load_db():
path = ConfigManager().get_data_dir_path() / "infoextractors"
path.mkdir(parents=True, exist_ok=True)
# os.makedirs(os.path.dirname(ConfigManager().get_data_dir_path() / "infoextractors"), exist_ok=True)
retirejs = load_database()
if retirejs is not None:
cleaned = strip_irrelevant_data(retirejs)
json_file_path = ConfigManager().get_data_dir_path() / "infoextractors" / "js_library_patterns.json"
json_file_path = (
ConfigManager().get_data_dir_path() / "infoextractors" / "js_library_patterns.json"
)
with open(json_file_path, "w") as f:
json.dump(cleaned, f, indent=4)
logger.info(f"Javascript library CVE database loaded.")
logger.info("Javascript library CVE database loaded.")
else:
logger.warning(f"javascript library CVE database did not load.")
logger.warning("javascript library CVE database did not load.")


load_db()
load_db()

0 comments on commit a0fb868

Please sign in to comment.