Agent: Return agent/dropper log path as a Path instead of str

This commit is contained in:
Mike Salvatore 2022-03-10 08:42:50 -05:00
parent 96069d3ae6
commit 17c3fa02b3
2 changed files with 4 additions and 3 deletions

View File

@ -289,7 +289,7 @@ class InfectionMonkey:
@staticmethod @staticmethod
def _send_log(): def _send_log():
monkey_log_path = get_agent_log_path() monkey_log_path = get_agent_log_path()
if os.path.exists(monkey_log_path): if monkey_log_path.is_file():
with open(monkey_log_path, "r") as f: with open(monkey_log_path, "r") as f:
log = f.read() log = f.read()
else: else:

View File

@ -3,12 +3,13 @@ import sys
import tempfile import tempfile
import time import time
from functools import lru_cache, partial from functools import lru_cache, partial
from pathlib import Path
# Cache the result of the call so that subsequent calls always return the same result # Cache the result of the call so that subsequent calls always return the same result
@lru_cache(maxsize=None) @lru_cache(maxsize=None)
def _get_log_path(monkey_arg: str) -> str: def _get_log_path(monkey_arg: str) -> Path:
return ( return Path(
os.path.expandvars(_generate_random_log_filepath(monkey_arg)) os.path.expandvars(_generate_random_log_filepath(monkey_arg))
if sys.platform == "win32" if sys.platform == "win32"
else _generate_random_log_filepath(monkey_arg) else _generate_random_log_filepath(monkey_arg)