Island: Use terminate signal's timestamp directly instead of creating an AgentSignals object in AgentSignals resource

This commit is contained in:
Shreya Malviya 2022-09-23 13:41:09 +05:30 committed by Mike Salvatore
parent f23a6c8fa4
commit cfe31f8dee
1 changed files with 7 additions and 5 deletions

View File

@ -5,7 +5,6 @@ from json import JSONDecodeError
from flask import request from flask import request
from monkey_island.cc.event_queue import IIslandEventQueue, IslandEventTopic from monkey_island.cc.event_queue import IIslandEventQueue, IslandEventTopic
from monkey_island.cc.models import AgentSignals as Signals
from monkey_island.cc.resources.AbstractResource import AbstractResource from monkey_island.cc.resources.AbstractResource import AbstractResource
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -22,11 +21,14 @@ class AgentSignals(AbstractResource):
def post(self): def post(self):
try: try:
signal = Signals(**request.json) terminate_timestamp = request.json["kill_time"]
if terminate_timestamp is None:
if signal.terminate is None:
raise ValueError("Terminate signal's timestamp is empty") raise ValueError("Terminate signal's timestamp is empty")
self._island_event_queue.publish(IslandEventTopic.TERMINATE_AGENTS, signal=signal)
self._island_event_queue.publish(
IslandEventTopic.TERMINATE_AGENTS, timestamp=terminate_timestamp
)
except (JSONDecodeError, TypeError, ValueError) as err: except (JSONDecodeError, TypeError, ValueError) as err:
return {"error": err}, HTTPStatus.BAD_REQUEST return {"error": err}, HTTPStatus.BAD_REQUEST