Island: Get rid of ResponseContents and ImportStatuses in new configuration resource

This commit is contained in:
Shreya Malviya 2022-06-22 07:48:34 -07:00
parent d861def86c
commit ec710d9e5f
1 changed files with 9 additions and 24 deletions

View File

@ -1,10 +1,9 @@
import json import json
from dataclasses import dataclass
from itertools import chain from itertools import chain
from typing import Mapping from typing import Mapping
import marshmallow import marshmallow
from flask import jsonify, request from flask import jsonify, make_response, request
from common.configuration.agent_configuration import AgentConfigurationSchema from common.configuration.agent_configuration import AgentConfigurationSchema
from common.configuration.default_agent_configuration import DEFAULT_AGENT_CONFIGURATION from common.configuration.default_agent_configuration import DEFAULT_AGENT_CONFIGURATION
@ -13,21 +12,6 @@ from monkey_island.cc.resources.AbstractResource import AbstractResource
from monkey_island.cc.resources.request_authentication import jwt_required from monkey_island.cc.resources.request_authentication import jwt_required
class ImportStatuses:
INVALID_CONFIGURATION = "invalid_configuration"
IMPORTED = "imported"
@dataclass
class ResponseContents:
import_status: str = ImportStatuses.IMPORTED
message: str = ""
status_code: int = 200
def form_response(self):
return self.__dict__
class AgentConfiguration(AbstractResource): class AgentConfiguration(AbstractResource):
urls = ["/api/agent-configuration"] urls = ["/api/agent-configuration"]
@ -63,14 +47,15 @@ class AgentConfiguration(AbstractResource):
try: try:
configuration_object = self._schema.loads(configuration_json) configuration_object = self._schema.loads(configuration_json)
self._agent_configuration_repository.store_configuration(configuration_object) self._agent_configuration_repository.store_configuration(configuration_object)
return ResponseContents().form_response() return make_response({}, 200)
except marshmallow.exceptions.ValidationError: except marshmallow.exceptions.ValidationError:
return ResponseContents( return make_response(
import_status=ImportStatuses.INVALID_CONFIGURATION, {
message="Invalid configuration supplied. " "message": "Invalid configuration supplied. "
"Maybe the format is outdated or the file has been corrupted.", "Maybe the format is outdated or the file has been corrupted."
status_code=400, },
).form_response() 400,
)
@staticmethod @staticmethod
def _remove_metadata_from_config(configuration_json: Mapping): def _remove_metadata_from_config(configuration_json: Mapping):