Agent: Remove unnecessary expandvars() in _get_log_path()

This commit is contained in:
Mike Salvatore 2022-03-10 08:56:34 -05:00
parent 2d2338f1f6
commit 45936c2f79
1 changed files with 1 additions and 11 deletions

View File

@ -1,5 +1,3 @@
import os
import sys
import tempfile import tempfile
import time import time
from functools import lru_cache, partial from functools import lru_cache, partial
@ -9,20 +7,12 @@ 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) -> Path: def _get_log_path(monkey_arg: str) -> Path:
return Path(
os.path.expandvars(_generate_random_log_filepath(monkey_arg))
if sys.platform == "win32"
else _generate_random_log_filepath(monkey_arg)
)
def _generate_random_log_filepath(monkey_arg: str) -> str:
prefix = f"infection-monkey-{monkey_arg}-" prefix = f"infection-monkey-{monkey_arg}-"
suffix = f"-{time.strftime('%Y-%m-%d-%H-%M-%S', time.gmtime())}.log" suffix = f"-{time.strftime('%Y-%m-%d-%H-%M-%S', time.gmtime())}.log"
_, monkey_log_path = tempfile.mkstemp(suffix=suffix, prefix=prefix) _, monkey_log_path = tempfile.mkstemp(suffix=suffix, prefix=prefix)
return monkey_log_path return Path(monkey_log_path)
get_agent_log_path = partial(_get_log_path, "monkey") get_agent_log_path = partial(_get_log_path, "monkey")