Island: Use make_response in GET agent_configuration

This commit is contained in:
Ilija Lazoroski 2022-06-23 14:26:14 +02:00 committed by Shreya Malviya
parent 48fab89e11
commit 39e4180dfe
1 changed files with 7 additions and 10 deletions

View File

@ -1,7 +1,7 @@
import json import json
import marshmallow import marshmallow
from flask import jsonify, make_response, request from flask import make_response, request
from common.configuration.agent_configuration import AgentConfigurationSchema from common.configuration.agent_configuration import AgentConfigurationSchema
from monkey_island.cc.repository import IAgentConfigurationRepository from monkey_island.cc.repository import IAgentConfigurationRepository
@ -20,22 +20,19 @@ class AgentConfiguration(AbstractResource):
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 = self._schema.dumps(configuration)
return jsonify(configuration_json=configuration_json) return make_response(configuration_json, 200)
@jwt_required @jwt_required
def post(self): def post(self):
request_contents = json.loads(request.data)
configuration_json = json.loads(request_contents["config"])
try: try:
configuration_object = self._schema.load(configuration_json) request_contents = json.loads(request.data)
configuration_object = self._schema.load(request_contents)
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: except (marshmallow.exceptions.ValidationError, json.JSONDecodeError) as err:
return make_response( return make_response(
{ {"message": f"Invalid configuration supplied: {err}"},
"message": "Invalid configuration supplied. "
"Maybe the format is outdated or the file has been corrupted."
},
400, 400,
) )