diff --git a/cyber_sandbox_creator/io/__init__.py b/cyber_sandbox_creator/io/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/cyber_sandbox_creator/io/reader.py b/cyber_sandbox_creator/io/reader.py new file mode 100644 index 0000000000000000000000000000000000000000..1620479624a5200d9067be4bac0c1ee136a3c365 --- /dev/null +++ b/cyber_sandbox_creator/io/reader.py @@ -0,0 +1,19 @@ +import yaml + +from pathlib import Path +from typing import Union, List, Dict + + +class Reader: + """Static methods for reading from files""" + + @staticmethod + def open_yaml(file_path: Path) -> Union[List, Dict]: + """Open a yaml file and return its content""" + try: + with file_path.open() as input_file: + return yaml.safe_load(input_file) + except yaml.YAMLError: + raise IOError(f"Could not parse yaml file {file_path}.") + except IOError: + raise IOError(f"Could not open yaml file {file_path}.")