From 029c3bb24d4571155eaf4db38550a0738033b7b7 Mon Sep 17 00:00:00 2001 From: Daniel Goldberg Date: Sun, 3 Nov 2019 15:01:26 -0500 Subject: [PATCH] Change property names. Add type hints --- monkey/infection_monkey/network/HostFinger.py | 11 ++++------- monkey/infection_monkey/network/HostScanner.py | 3 ++- .../infection_monkey/network/fingerprinter_manager.py | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/monkey/infection_monkey/network/HostFinger.py b/monkey/infection_monkey/network/HostFinger.py index e660c8c6c..1eecabe6f 100644 --- a/monkey/infection_monkey/network/HostFinger.py +++ b/monkey/infection_monkey/network/HostFinger.py @@ -3,8 +3,9 @@ from abc import ABCMeta, abstractproperty, abstractmethod from infection_monkey.config import WormConfiguration -class HostFinger(object, metaclass=ABCMeta): - @abstractproperty +class HostFinger(metaclass=ABCMeta): + @property + @abstractmethod def _SCANNED_SERVICE(self): pass @@ -18,9 +19,5 @@ class HostFinger(object, metaclass=ABCMeta): raise NotImplementedError() @staticmethod - def should_run(class_name): - """ - Decides if post breach action is enabled in config - :return: True if it needs to be ran, false otherwise - """ + def should_run(class_name: str) -> bool: return class_name in WormConfiguration.finger_classes diff --git a/monkey/infection_monkey/network/HostScanner.py b/monkey/infection_monkey/network/HostScanner.py index f32af1c5e..c6e730c3f 100644 --- a/monkey/infection_monkey/network/HostScanner.py +++ b/monkey/infection_monkey/network/HostScanner.py @@ -1,7 +1,8 @@ from abc import ABCMeta, abstractmethod -class HostScanner(object, metaclass=ABCMeta): +class HostScanner(metaclass=ABCMeta): + @property @abstractmethod def is_host_alive(self, host): raise NotImplementedError() diff --git a/monkey/infection_monkey/network/fingerprinter_manager.py b/monkey/infection_monkey/network/fingerprinter_manager.py index 5eaeeafdb..9a6c83082 100644 --- a/monkey/infection_monkey/network/fingerprinter_manager.py +++ b/monkey/infection_monkey/network/fingerprinter_manager.py @@ -1,11 +1,12 @@ import logging +from typing import Sequence from infection_monkey.utils.load_plugins import get_instances from infection_monkey.network.HostFinger import HostFinger LOG = logging.getLogger(__name__) -def get_fingerprint_instances(): +def get_fingerprint_instances() -> Sequence[HostFinger]: """ Returns the fingerprint objects according to configuration as a list :return: A list of HostFinger objects.