From c79f62e682135ad233f988654d46c6d32021be18 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 16 Jun 2022 14:57:50 -0400 Subject: [PATCH] Common: Add PluginConfiguration --- monkey/common/agent_configuration | 0 monkey/common/configuration/__init__.py | 1 + .../configuration/agent_configuration.py | 21 +++++++++++++++++++ .../common/test_agent_configuration.py | 12 +++++++++++ vulture_allowlist.py | 6 ++++++ 5 files changed, 40 insertions(+) create mode 100644 monkey/common/agent_configuration create mode 100644 monkey/common/configuration/__init__.py create mode 100644 monkey/common/configuration/agent_configuration.py create mode 100644 monkey/tests/unit_tests/common/test_agent_configuration.py diff --git a/monkey/common/agent_configuration b/monkey/common/agent_configuration new file mode 100644 index 000000000..e69de29bb diff --git a/monkey/common/configuration/__init__.py b/monkey/common/configuration/__init__.py new file mode 100644 index 000000000..a40b7a97e --- /dev/null +++ b/monkey/common/configuration/__init__.py @@ -0,0 +1 @@ +from .agent_configuration import PluginConfiguration, PluginConfigurationSchema diff --git a/monkey/common/configuration/agent_configuration.py b/monkey/common/configuration/agent_configuration.py new file mode 100644 index 000000000..fbcc4872d --- /dev/null +++ b/monkey/common/configuration/agent_configuration.py @@ -0,0 +1,21 @@ +from dataclasses import dataclass + +from marshmallow import RAISE, Schema, fields, post_load + + +@dataclass(frozen=True) +class PluginConfiguration: + name: str + options: dict + + +class PluginConfigurationSchema(Schema): + class Meta: + unknown = RAISE + + name = fields.Str() + options = fields.Mapping() + + @post_load + def make_plugin_configuration(self, data, **kwargs): + return PluginConfiguration(**data) diff --git a/monkey/tests/unit_tests/common/test_agent_configuration.py b/monkey/tests/unit_tests/common/test_agent_configuration.py new file mode 100644 index 000000000..53555680d --- /dev/null +++ b/monkey/tests/unit_tests/common/test_agent_configuration.py @@ -0,0 +1,12 @@ +from common.configuration import PluginConfigurationSchema + + +def test_build_plugin_configuration(): + name = "bond" + options = {"gun": "Walther PPK", "car": "Aston Martin DB5"} + pcs = PluginConfigurationSchema() + + pc = pcs.load({"name": name, "options": options}) + + assert pc.name == name + assert pc.options == options diff --git a/vulture_allowlist.py b/vulture_allowlist.py index ab09127b3..73961d4d7 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -183,6 +183,12 @@ 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) + + # TODO DELETE AFTER RESOURCE REFACTORING NetworkMap Arc.dst_machine