forked from p15670423/monkey
Island: Make FileNotFoundError inherit UnknownRecordError instead of RetrievalError + add TODO for updating the rest of the code
This commit is contained in:
parent
64990eea0e
commit
8f46b3b9fd
|
@ -1,14 +1,8 @@
|
||||||
import io
|
import io
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from monkey_island.cc import repository
|
|
||||||
from monkey_island.cc.models import AgentID
|
from monkey_island.cc.models import AgentID
|
||||||
from monkey_island.cc.repository import (
|
from monkey_island.cc.repository import IAgentLogRepository, IFileRepository, RetrievalError
|
||||||
IAgentLogRepository,
|
|
||||||
IFileRepository,
|
|
||||||
RetrievalError,
|
|
||||||
UnknownRecordError,
|
|
||||||
)
|
|
||||||
|
|
||||||
AGENT_LOG_FILE_NAME_PATTERN = "agent-*.log"
|
AGENT_LOG_FILE_NAME_PATTERN = "agent-*.log"
|
||||||
AGENT_LOG_FILE_NAME_REGEX = re.compile(r"^agent-[\w-]+.log$")
|
AGENT_LOG_FILE_NAME_REGEX = re.compile(r"^agent-[\w-]+.log$")
|
||||||
|
@ -28,8 +22,6 @@ class FileAgentLogRepository(IAgentLogRepository):
|
||||||
with self._file_repository.open_file(self._get_agent_log_file_name(agent_id)) as f:
|
with self._file_repository.open_file(self._get_agent_log_file_name(agent_id)) as f:
|
||||||
log_contents = f.read().decode()
|
log_contents = f.read().decode()
|
||||||
return log_contents
|
return log_contents
|
||||||
except repository.FileNotFoundError as err:
|
|
||||||
raise UnknownRecordError(err)
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise RetrievalError(f"Error retrieving the agent logs: {err}")
|
raise RetrievalError(f"Error retrieving the agent logs: {err}")
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import abc
|
import abc
|
||||||
from typing import BinaryIO
|
from typing import BinaryIO
|
||||||
|
|
||||||
from monkey_island.cc.repository import RetrievalError
|
from monkey_island.cc.repository import UnknownRecordError
|
||||||
|
|
||||||
|
|
||||||
class FileNotFoundError(RetrievalError):
|
# TODO: Remove this and use UnknownRecordError directly wherever needed.
|
||||||
|
class FileNotFoundError(UnknownRecordError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue