Merge pull request #2151 from guardicore/add-get_file_contents-to-file-utils

Add get_file_contents() to file utils
This commit is contained in:
Shreya Malviya 2022-08-02 18:29:06 +05:30 committed by GitHub
commit 7f915d987a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -3,7 +3,7 @@ from pathlib import Path
from monkey_island.cc.resources.AbstractResource import AbstractResource from monkey_island.cc.resources.AbstractResource import AbstractResource
from monkey_island.cc.resources.request_authentication import jwt_required from monkey_island.cc.resources.request_authentication import jwt_required
from monkey_island.cc.server_utils.island_logger import get_log_file_contents from monkey_island.cc.server_utils.file_utils import get_text_file_contents
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -17,6 +17,6 @@ class IslandLog(AbstractResource):
@jwt_required @jwt_required
def get(self): def get(self):
try: try:
return get_log_file_contents(self._island_log_file_path) return get_text_file_contents(self._island_log_file_path)
except Exception: except Exception:
logger.error("Monkey Island logs failed to download", exc_info=True) logger.error("Monkey Island logs failed to download", exc_info=True)

View File

@ -21,6 +21,12 @@ if is_windows_os():
import monkey_island.cc.server_utils.windows_permissions as windows_permissions import monkey_island.cc.server_utils.windows_permissions as windows_permissions
def get_text_file_contents(file_path: Path) -> str:
with open(file_path, "rt") as f:
file_contents = f.read()
return file_contents
def create_secure_directory(path: Path): def create_secure_directory(path: Path):
if not path.is_dir(): if not path.is_dir():
if is_windows_os(): if is_windows_os():

View File

@ -33,12 +33,6 @@ def get_log_file_path(data_dir: Path) -> Path:
return data_dir / ISLAND_LOG_FILENAME return data_dir / ISLAND_LOG_FILENAME
def get_log_file_contents(log_file_path: Path) -> str:
with open(log_file_path, "rt") as f:
log_file = f.read()
return log_file
def setup_default_failsafe_logging(): def setup_default_failsafe_logging():
logger = logging.getLogger() logger = logging.getLogger()
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)