type cleanup

pull/12/head
Thorsten Sick 3 years ago
parent 5eeaa02b4d
commit df03e0c74e

@ -9,8 +9,10 @@ from plugins.base.attack import AttackPlugin
from plugins.base.machinery import MachineryPlugin from plugins.base.machinery import MachineryPlugin
from plugins.base.sensor import SensorPlugin from plugins.base.sensor import SensorPlugin
from plugins.base.vulnerability_plugin import VulnerabilityPlugin from plugins.base.vulnerability_plugin import VulnerabilityPlugin
import straight.plugin import straight.plugin # type: ignore
from app.interface_sfx import CommandlineColors from app.interface_sfx import CommandlineColors
from app.attack_log import AttackLog
# from app.interface_sfx import CommandlineColors # from app.interface_sfx import CommandlineColors
sections = [{"name": "Vulnerabilities", sections = [{"name": "Vulnerabilities",
@ -27,7 +29,7 @@ sections = [{"name": "Vulnerabilities",
class PluginManager(): class PluginManager():
""" Manage plugins """ """ Manage plugins """
def __init__(self, attack_logger): def __init__(self, attack_logger: AttackLog):
""" """
@param attack_logger: The attack logger to use @param attack_logger: The attack logger to use

@ -4,24 +4,25 @@
import os import os
import yaml import yaml
# from shutil import copy # from shutil import copy
from app.exceptions import PluginError from app.exceptions import PluginError # type: ignore
import app.exceptions import app.exceptions # type: ignore
from typing import Optional
class BasePlugin(): class BasePlugin():
""" Base class for plugins """ """ Base class for plugins """
required_files = None # a list of files shipped with the plugin to be installed required_files: list[str] = [] # a list of files shipped with the plugin to be installed
name = None # The name of the plugin name: str = "" # The name of the plugin
alternative_names = [] # The is an optional list of alternative names alternative_names: list[str] = [] # The is an optional list of alternative names
description = None # The description of this plugin description: Optional[str] = None # The description of this plugin
def __init__(self): def __init__(self) -> None:
# self.machine = None # self.machine = None
self.plugin_path = None self.plugin_path = None
self.machine_plugin = None self.machine_plugin = None
self.sysconf = {} # self.sysconf = {}
self.conf = {} self.conf: dict = {}
self.attack_logger = None self.attack_logger = None
self.default_config_name = "default_config.yaml" self.default_config_name = "default_config.yaml"
@ -126,7 +127,7 @@ class BasePlugin():
raise NotImplementedError raise NotImplementedError
def get_names(self) -> []: def get_names(self) -> list[str]:
""" Adds the name of the plugin to the alternative names and returns the list """ """ Adds the name of the plugin to the alternative names and returns the list """
res = set() res = set()
@ -183,20 +184,20 @@ class BasePlugin():
if self.conf is None: if self.conf is None:
self.conf = {} self.conf = {}
def get_config_section_name(self): def get_config_section_name(self) -> str:
""" Returns the name for the config sub-section to use for this plugin. """ Returns the name for the config sub-section to use for this plugin.
Defaults to the name of the plugin. This method should be overwritten if it gets more complicated """ Defaults to the name of the plugin. This method should be overwritten if it gets more complicated """
return self.get_name() return self.get_name()
def main_path(self): # pylint:disable=no-self-use def main_path(self) -> str: # pylint:disable=no-self-use
""" Returns the main path of the Purple Dome installation """ """ Returns the main path of the Purple Dome installation """
app_dir = os.path.dirname(app.exceptions.__file__) app_dir = os.path.dirname(app.exceptions.__file__)
return os.path.split(app_dir)[0] return os.path.split(app_dir)[0]
def vprint(self, text, verbosity): def vprint(self, text: str, verbosity: int):
""" verbosity based stdout printing """ verbosity based stdout printing
0: Errors only 0: Errors only
@ -207,5 +208,5 @@ class BasePlugin():
@param text: The text to print @param text: The text to print
@param verbosity: the verbosity level the text has. @param verbosity: the verbosity level the text has.
""" """
if self.attack_logger is not None:
self.attack_logger.vprint(text, verbosity) self.attack_logger.vprint(text, verbosity)

@ -31,7 +31,7 @@ class VagrantPlugin(SSHFeatures, MachineryPlugin):
self.connection = None self.connection = None
self.vagrantfilepath = None self.vagrantfilepath = None
self.vagrantfile = None self.vagrantfile = None
self.sysconf = {} # self.sysconf = {}
def process_config(self, config): def process_config(self, config):
""" Machine specific processing of configuration """ """ Machine specific processing of configuration """

Loading…
Cancel
Save