diff --git a/monkey/common/configuration/agent_configuration.py b/monkey/common/configuration/agent_configuration.py index 8ba9e998b..a1f2eb70c 100644 --- a/monkey/common/configuration/agent_configuration.py +++ b/monkey/common/configuration/agent_configuration.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from dataclasses import dataclass from typing import List @@ -32,6 +34,10 @@ class AgentConfiguration: def from_json(config_json: dict): return AgentConfigurationSchema().loads(config_json) + @staticmethod + def to_json(config: AgentConfiguration) -> str: + return AgentConfigurationSchema().dumps(config) + 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 6156a0b69..134a18a91 100644 --- a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py @@ -198,3 +198,11 @@ def test_from_json(): config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON) assert schema.dump(config) == dict_ + + +def test_to_json(): + config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON) + + assert json.loads(AgentConfiguration.to_json(config)) == json.loads( + DEFAULT_AGENT_CONFIGURATION_JSON + )