diff --git a/monkey/common/configuration/agent_configuration.py b/monkey/common/configuration/agent_configuration.py index 95592ecb7..6ac8f9a2a 100644 --- a/monkey/common/configuration/agent_configuration.py +++ b/monkey/common/configuration/agent_configuration.py @@ -2,6 +2,9 @@ from dataclasses import dataclass from typing import Dict, List from marshmallow import RAISE, Schema, fields, post_load +from marshmallow_enum import EnumField + +from common import OperatingSystems @dataclass(frozen=True) @@ -48,7 +51,7 @@ class PluginConfigurationSchema(Schema): class ExploiterConfiguration: name: str options: Dict - supported_os: List[str] + supported_os: List[OperatingSystems] class ExploiterConfigurationSchema(Schema): @@ -57,7 +60,7 @@ class ExploiterConfigurationSchema(Schema): name = fields.Str() options = fields.Mapping() - supported_os = fields.List(fields.Str()) + supported_os = fields.List(EnumField(OperatingSystems)) @post_load def make_exploiter_configuration(self, data, **kwargs): diff --git a/monkey/tests/unit_tests/common/test_agent_configuration.py b/monkey/tests/unit_tests/common/test_agent_configuration.py index 7854a48ea..6fd5ac290 100644 --- a/monkey/tests/unit_tests/common/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/test_agent_configuration.py @@ -1,3 +1,4 @@ +from common import OperatingSystems from common.configuration import ( CustomPBAConfigurationSchema, ExploiterConfigurationSchema, @@ -41,10 +42,12 @@ def test_custom_pba_configuration_schema(): def test_exploiter_configuration_schema(): name = "bond" options = {"gun": "Walther PPK", "car": "Aston Martin DB5"} - supported_os = ["linux", "windows"] + supported_os = [OperatingSystems.LINUX, OperatingSystems.WINDOWS] schema = ExploiterConfigurationSchema() - config = schema.load({"name": name, "options": options, "supported_os": supported_os}) + config = schema.load( + {"name": name, "options": options, "supported_os": [os_.name for os_ in supported_os]} + ) assert config.name == name assert config.options == options diff --git a/vulture_allowlist.py b/vulture_allowlist.py index dec1aa7dd..7e1c4056a 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -184,11 +184,13 @@ architecture # unused variable (monkey/infection_monkey/exploit/caching_agent_r response_code # unused variable (monkey/monkey_island/cc/services/aws/aws_command_runner.py:26) # Agent Configuration -Meta # unused class(monkey/common/configuration/agent_configuration.py:13) -unknown # unused variable(monkey/common/configuration/agent_configuration.py:14) -make_plugin_configuration # unused method(monkey/common/configuration/agent_configuration.py:19) -make_custom_pba_configuration # unused method(monkey/common/configuration/agent_configuration.py:34) -make_exploiter_configuration # unused method(monkey/common/configuration/agent_configuration.py:62) +Meta # unused class (monkey/common/configuration/agent_configuration.py:13) +unknown # unused variable (monkey/common/configuration/agent_configuration.py:14) +make_plugin_configuration # unused method (monkey/common/configuration/agent_configuration.py:19) +make_custom_pba_configuration # unused method (monkey/common/configuration/agent_configuration.py:34) +make_exploiter_configuration # unused method (monkey/common/configuration/agent_configuration.py:62) +LINUX # unused variable (monkey/common/operating_systems.py:5) +WINDOWS # unused variable (monkey/common/operating_systems.py:6) # TODO DELETE AFTER RESOURCE REFACTORING