From 8e40e44263dd9765e6f3a785fc71d38b1f878589 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 24 Jun 2021 12:09:30 -0400 Subject: [PATCH] agent: Add BatchableTelemMixin Adds an implementation as a mixin of the two methods specified by IBatchableTelem. --- .../telemetry/batchable_telem_mixin.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 monkey/infection_monkey/telemetry/batchable_telem_mixin.py diff --git a/monkey/infection_monkey/telemetry/batchable_telem_mixin.py b/monkey/infection_monkey/telemetry/batchable_telem_mixin.py new file mode 100644 index 000000000..4189f0cf0 --- /dev/null +++ b/monkey/infection_monkey/telemetry/batchable_telem_mixin.py @@ -0,0 +1,22 @@ +from typing import Iterable + +from infection_monkey.telemetry.i_batchable_telem import IBatchableTelem + + +class BatchableTelemMixin: + """ + Implements the IBatchableTelem interface methods using a list. + """ + + @property + def _telemetry_entries(self): + if not hasattr(self, "_list"): + self._list = [] + + return self._list + + def get_telemetry_entries(self) -> Iterable: + return self._telemetry_entries + + def add_telemetry_to_batch(self, telemetry: IBatchableTelem): + self._telemetry_entries.extend(telemetry.get_telemetry_entries())