Island: Publish SET_MODE event in IslandMode's PUT

This commit is contained in:
Shreya Malviya 2022-09-21 14:38:08 +05:30
parent 5675724843
commit 67e280fd7a
1 changed files with 6 additions and 1 deletions

View File

@ -4,6 +4,7 @@ from http import HTTPStatus
from flask import request
from monkey_island.cc.event_queue import IIslandEventQueue, IslandEventTopic
from monkey_island.cc.models import IslandMode as IslandModeEnum
from monkey_island.cc.resources.AbstractResource import AbstractResource
from monkey_island.cc.resources.request_authentication import jwt_required
@ -15,8 +16,11 @@ logger = logging.getLogger(__name__)
class IslandMode(AbstractResource):
urls = ["/api/island/mode"]
def __init__(self, island_mode_service: IslandModeService):
def __init__(
self, island_mode_service: IslandModeService, island_event_queue: IIslandEventQueue
):
self._island_mode_service = island_mode_service
self._island_event_queue = island_event_queue
@jwt_required
def put(self):
@ -24,6 +28,7 @@ class IslandMode(AbstractResource):
mode = IslandModeEnum(request.json)
self._island_mode_service.set_mode(mode)
self._island_event_queue.publish(topic=IslandEventTopic.SET_MODE, event=mode)
return {}, HTTPStatus.NO_CONTENT
except (AttributeError, json.decoder.JSONDecodeError):