From a5e805564d0ef775f910d26201b8e7dc3ca4bcfd Mon Sep 17 00:00:00 2001 From: Daniel Sagi Date: Thu, 27 Jan 2022 21:36:41 +0200 Subject: [PATCH] ran black to format --- kube_hunter/__main__.py | 2 +- kube_hunter/conf/__init__.py | 9 ++++----- kube_hunter/core/events/handler.py | 10 +++++----- kube_hunter/modules/report/dispatchers.py | 6 +----- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/kube_hunter/__main__.py b/kube_hunter/__main__.py index 024e488..fb244c8 100755 --- a/kube_hunter/__main__.py +++ b/kube_hunter/__main__.py @@ -30,7 +30,7 @@ config = Config( service_account_token=args.service_account_token, kubeconfig=args.kubeconfig, enable_cve_hunting=args.enable_cve_hunting, - custom=args.custom + custom=args.custom, ) setup_logger(args.log, args.log_file) set_config(config) diff --git a/kube_hunter/conf/__init__.py b/kube_hunter/conf/__init__.py index cfa7ed2..2f856d8 100644 --- a/kube_hunter/conf/__init__.py +++ b/kube_hunter/conf/__init__.py @@ -1,12 +1,10 @@ from dataclasses import dataclass, field from typing import Any, Optional + def get_default_core_hunters(): - return [ - "FromPodHostDiscovery", - "HostDiscovery", - "PortDiscovery" - ] + return ["FromPodHostDiscovery", "HostDiscovery", "PortDiscovery"] + @dataclass class Config: @@ -54,6 +52,7 @@ class Config: _config: Optional[Config] = None + def get_config() -> Config: if not _config: raise ValueError("Configuration is not initialized") diff --git a/kube_hunter/core/events/handler.py b/kube_hunter/core/events/handler.py index dfd5c79..8f190bd 100644 --- a/kube_hunter/core/events/handler.py +++ b/kube_hunter/core/events/handler.py @@ -267,21 +267,21 @@ class EventQueue(Queue): Returns true if: 1. partial hunt is disabled 2. partial hunt is enabled and hunter is in core hunter class - 3. partial hunt is enabled and hunter is specified in config.partial + 3. partial hunt is enabled and hunter is specified in config.partial @param target_hunter: hunter class for registration check - """ + """ config = get_config() if not config.custom: return True - + hunter_class_name = target_hunter.__name__ if hunter_class_name in self.core_hunters or hunter_class_name in config.custom: return True - + return False - def subscribe_event(self, event, hook=None, predicate=None, is_register=True): + def subscribe_event(self, event, hook=None, predicate=None, is_register=True): if not is_register: return if not self.allowed_for_custom_registration(hook): diff --git a/kube_hunter/modules/report/dispatchers.py b/kube_hunter/modules/report/dispatchers.py index 1f17b7c..1f1a5b6 100644 --- a/kube_hunter/modules/report/dispatchers.py +++ b/kube_hunter/modules/report/dispatchers.py @@ -12,11 +12,7 @@ class HTTPDispatcher: dispatch_url = os.environ.get("KUBEHUNTER_HTTP_DISPATCH_URL", "https://localhost/") try: r = requests.request( - dispatch_method, - dispatch_url, - json=report, - headers={"Content-Type": "application/json"}, - verify=False + dispatch_method, dispatch_url, json=report, headers={"Content-Type": "application/json"}, verify=False ) r.raise_for_status() logger.info(f"Report was dispatched to: {dispatch_url}")