From 543c063f7bb48ffff6bdac20f1b19af495604218 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Wed, 28 Sep 2022 14:52:19 +0200 Subject: [PATCH] Island: Add AgentLogs endpoint --- monkey/monkey_island/cc/resources/__init__.py | 1 + .../monkey_island/cc/resources/agent_logs.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 monkey/monkey_island/cc/resources/agent_logs.py diff --git a/monkey/monkey_island/cc/resources/__init__.py b/monkey/monkey_island/cc/resources/__init__.py index 937766e2b..e6c2db648 100644 --- a/monkey/monkey_island/cc/resources/__init__.py +++ b/monkey/monkey_island/cc/resources/__init__.py @@ -11,3 +11,4 @@ from .pba_file_download import PBAFileDownload from .agent_events import AgentEvents from .agents import Agents from .agent_signals import AgentSignals, TerminateAllAgents +from .agent_logs import AgentLogs diff --git a/monkey/monkey_island/cc/resources/agent_logs.py b/monkey/monkey_island/cc/resources/agent_logs.py new file mode 100644 index 000000000..64270fd64 --- /dev/null +++ b/monkey/monkey_island/cc/resources/agent_logs.py @@ -0,0 +1,27 @@ +from http import HTTPStatus + +from flask import request + +from monkey_island.cc.repository import IAgentLogRepository +from monkey_island.cc.resources.AbstractResource import AbstractResource +from monkey_island.cc.resources.request_authentication import jwt_required + + +class AgentLogs(AbstractResource): + urls = ["/api/agent-logs/"] + + def __init__(self, agent_log_repository: IAgentLogRepository): + self._agent_log_repository = agent_log_repository + + @jwt_required + def get(self, agent_id: str): + agent_log = self._agent_log_repository.get_agent_log(agent_id) + + return agent_log, HTTPStatus.OK + + def put(self, agent_id: str): + agent_data = request.json["log_contents"] + + self._agent_log_repository.upsert_agent_log(agent_id, agent_data) + + return {}, HTTPStatus.NO_CONTENT