Island: Remove POST method from AgentSignals resource

This commit is contained in:
Shreya Malviya 2022-09-23 17:54:00 +05:30 committed by Mike Salvatore
parent c586623b8b
commit 105cc60f4b
1 changed files with 1 additions and 24 deletions

View File

@ -1,10 +1,6 @@
import logging
from http import HTTPStatus
from json import JSONDecodeError
from flask import request
from monkey_island.cc.event_queue import IIslandEventQueue, IslandEventTopic
from monkey_island.cc.resources.AbstractResource import AbstractResource
from monkey_island.cc.services import AgentSignalsService
@ -12,33 +8,14 @@ logger = logging.getLogger(__name__)
class AgentSignals(AbstractResource):
urls = ["/api/agent-signals/terminate-all", "/api/agent-signals/<string:agent_id>"]
urls = ["/api/agent-signals/<string:agent_id>"]
def __init__(
self,
island_event_queue: IIslandEventQueue,
agent_signals_service: AgentSignalsService,
):
self._island_event_queue = island_event_queue
self._agent_signals_service = agent_signals_service
def post(self):
try:
terminate_timestamp = request.json["terminate_time"]
if terminate_timestamp is None:
raise ValueError("Terminate signal's timestamp is empty")
elif terminate_timestamp <= 0:
raise ValueError("Terminate signal's timestamp is not a positive integer")
self._island_event_queue.publish(
IslandEventTopic.TERMINATE_AGENTS, timestamp=terminate_timestamp
)
except (JSONDecodeError, TypeError, ValueError, KeyError) as err:
return {"error": err}, HTTPStatus.BAD_REQUEST
return {}, HTTPStatus.NO_CONTENT
def get(self, agent_id: str):
agent_signals = self._agent_signals_service.get_signals(agent_id)
return agent_signals.dict(simplify=True), HTTPStatus.OK