Island: Use {from,to}_json() in resources

This commit is contained in:
Mike Salvatore 2022-06-24 12:33:12 -04:00
parent a1baaae76a
commit 07d1d9c45a
1 changed files with 3 additions and 4 deletions

View File

@ -3,7 +3,7 @@ import json
import marshmallow import marshmallow
from flask import make_response, request from flask import make_response, request
from common.configuration.agent_configuration import AgentConfigurationSchema from common.configuration.agent_configuration import AgentConfiguration as AgentConfigurationObject
from monkey_island.cc.repository import IAgentConfigurationRepository from monkey_island.cc.repository import IAgentConfigurationRepository
from monkey_island.cc.resources.AbstractResource import AbstractResource 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
@ -14,19 +14,18 @@ class AgentConfiguration(AbstractResource):
def __init__(self, agent_configuration_repository: IAgentConfigurationRepository): def __init__(self, agent_configuration_repository: IAgentConfigurationRepository):
self._agent_configuration_repository = agent_configuration_repository self._agent_configuration_repository = agent_configuration_repository
self._schema = AgentConfigurationSchema()
@jwt_required @jwt_required
def get(self): def get(self):
configuration = self._agent_configuration_repository.get_configuration() configuration = self._agent_configuration_repository.get_configuration()
configuration_json = self._schema.dumps(configuration) configuration_json = AgentConfigurationObject.to_json(configuration)
return make_response(configuration_json, 200) return make_response(configuration_json, 200)
@jwt_required @jwt_required
def post(self): def post(self):
try: try:
configuration_object = self._schema.loads(request.data) configuration_object = AgentConfigurationObject.from_json(request.data)
self._agent_configuration_repository.store_configuration(configuration_object) self._agent_configuration_repository.store_configuration(configuration_object)
return make_response({}, 200) return make_response({}, 200)
except (marshmallow.exceptions.ValidationError, json.JSONDecodeError) as err: except (marshmallow.exceptions.ValidationError, json.JSONDecodeError) as err: