Island: Modify IslandLog resource to fetch and return log file contents

This commit is contained in:
Shreya Malviya 2022-08-01 13:33:24 +05:30
parent b89ffbae24
commit 977860efb2
1 changed files with 6 additions and 2 deletions

View File

@ -3,7 +3,6 @@ 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.services.island_logs import IslandLogService
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -17,6 +16,11 @@ class IslandLog(AbstractResource):
@jwt_required @jwt_required
def get(self): def get(self):
try: try:
return IslandLogService.get_log_file() return self._get_log_file_contents()
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)
def _get_log_file_contents(self):
with open(self._island_log_file_path, "rt") as f:
log_file = f.read()
return {"log_file": log_file}