Island: Remove POST method from AgentSignals resource
This commit is contained in:
parent
c586623b8b
commit
105cc60f4b
|
@ -1,10 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
from http import HTTPStatus
|
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.resources.AbstractResource import AbstractResource
|
||||||
from monkey_island.cc.services import AgentSignalsService
|
from monkey_island.cc.services import AgentSignalsService
|
||||||
|
|
||||||
|
@ -12,33 +8,14 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AgentSignals(AbstractResource):
|
class AgentSignals(AbstractResource):
|
||||||
urls = ["/api/agent-signals/terminate-all", "/api/agent-signals/<string:agent_id>"]
|
urls = ["/api/agent-signals/<string:agent_id>"]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
island_event_queue: IIslandEventQueue,
|
|
||||||
agent_signals_service: AgentSignalsService,
|
agent_signals_service: AgentSignalsService,
|
||||||
):
|
):
|
||||||
self._island_event_queue = island_event_queue
|
|
||||||
self._agent_signals_service = agent_signals_service
|
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):
|
def get(self, agent_id: str):
|
||||||
agent_signals = self._agent_signals_service.get_signals(agent_id)
|
agent_signals = self._agent_signals_service.get_signals(agent_id)
|
||||||
return agent_signals.dict(simplify=True), HTTPStatus.OK
|
return agent_signals.dict(simplify=True), HTTPStatus.OK
|
||||||
|
|
Loading…
Reference in New Issue