Files
prowler/lib/utils/utils.py
2022-06-22 16:48:10 +02:00

29 lines
677 B
Python

import json
import sys
from io import TextIOWrapper
from typing import Any
from lib.logger import logger
def open_file(input_file: str) -> TextIOWrapper:
try:
# First recover the available groups in groups.json
f = open(input_file)
except Exception as e:
logger.critical(f"{input_file}: {e.__class__.__name__}")
sys.exit()
else:
return f
# Parse checks from file
def parse_json_file(input_file: TextIOWrapper) -> Any:
try:
json_file = json.load(input_file)
except Exception as e:
logger.critical(f"{input_file.name}: {e.__class__.__name__}")
sys.exit()
else:
return json_file