diff --git a/monkey/common/configuration/agent_configuration.py b/monkey/common/configuration/agent_configuration.py index 36fa24b85..8ba9e998b 100644 --- a/monkey/common/configuration/agent_configuration.py +++ b/monkey/common/configuration/agent_configuration.py @@ -28,6 +28,10 @@ class AgentConfiguration: def from_dict(dict_: dict): return AgentConfigurationSchema().load(dict_) + @staticmethod + def from_json(config_json: dict): + return AgentConfigurationSchema().loads(config_json) + class AgentConfigurationSchema(Schema): keep_tunnel_open_time = fields.Float() diff --git a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py index 13cd106a8..6156a0b69 100644 --- a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py @@ -189,3 +189,12 @@ def test_from_dict(): config = AgentConfiguration.from_dict(dict_) assert schema.dump(config) == dict_ + + +def test_from_json(): + schema = AgentConfigurationSchema() + dict_ = json.loads(DEFAULT_AGENT_CONFIGURATION_JSON) + + config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON) + + assert schema.dump(config) == dict_