From eaf9b6a8d15355a280bd01d92562e5534b0d4223 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Mon, 4 Jan 2021 15:46:53 +0200 Subject: [PATCH] Renamed cloud providers enum to camel case --- monkey/common/cloud/scoutsuite_consts.py | 2 +- .../system_info/collectors/aws_collector.py | 4 ++-- .../scoutsuite_collector/scoutsuite_collector.py | 4 ++-- monkey/infection_monkey/telemetry/base_telem.py | 8 ++++---- .../zero_trust/scoutsuite_auth/scoutsuite_auth.py | 10 +++++----- .../zero_trust/scoutsuite/scoutsuite_auth_service.py | 6 +++--- .../cc/services/zero_trust/zero_trust_service.py | 3 +-- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/monkey/common/cloud/scoutsuite_consts.py b/monkey/common/cloud/scoutsuite_consts.py index 86411e179..4db862a4a 100644 --- a/monkey/common/cloud/scoutsuite_consts.py +++ b/monkey/common/cloud/scoutsuite_consts.py @@ -1,7 +1,7 @@ from enum import Enum -class PROVIDERS(Enum): +class CloudProviders(Enum): AWS = 'aws' AZURE = 'azure' GCP = 'gcp' diff --git a/monkey/infection_monkey/system_info/collectors/aws_collector.py b/monkey/infection_monkey/system_info/collectors/aws_collector.py index f6435f4db..aab70066e 100644 --- a/monkey/infection_monkey/system_info/collectors/aws_collector.py +++ b/monkey/infection_monkey/system_info/collectors/aws_collector.py @@ -1,7 +1,7 @@ import logging from common.cloud.aws.aws_instance import AwsInstance -from common.cloud.scoutsuite_consts import PROVIDERS +from common.cloud.scoutsuite_consts import CloudProviders from common.common_consts.system_info_collectors_names import AWS_COLLECTOR from common.network.network_utils import is_running_on_island from infection_monkey.system_info.collectors.scoutsuite_collector.scoutsuite_collector import scan_cloud_security @@ -21,7 +21,7 @@ class AwsCollector(SystemInfoCollector): logger.info("Collecting AWS info") if is_running_on_island(): logger.info("Attempting to scan AWS security with ScoutSuite.") - scan_cloud_security(cloud_type=PROVIDERS.AWS) + scan_cloud_security(cloud_type=CloudProviders.AWS) else: logger.info("Didn't scan AWS security with ScoutSuite, because not on island.") aws = AwsInstance() diff --git a/monkey/infection_monkey/system_info/collectors/scoutsuite_collector/scoutsuite_collector.py b/monkey/infection_monkey/system_info/collectors/scoutsuite_collector/scoutsuite_collector.py index 6b59af720..acf63104a 100644 --- a/monkey/infection_monkey/system_info/collectors/scoutsuite_collector/scoutsuite_collector.py +++ b/monkey/infection_monkey/system_info/collectors/scoutsuite_collector/scoutsuite_collector.py @@ -1,14 +1,14 @@ import logging import infection_monkey.system_info.collectors.scoutsuite_collector.scoutsuite_api as scoutsuite_api -from common.cloud.scoutsuite_consts import PROVIDERS +from common.cloud.scoutsuite_consts import CloudProviders from infection_monkey.config import WormConfiguration from infection_monkey.telemetry.scoutsuite_telem import ScoutSuiteTelem logger = logging.getLogger(__name__) -def scan_cloud_security(cloud_type: PROVIDERS): +def scan_cloud_security(cloud_type: CloudProviders): try: results = run_scoutsuite(cloud_type.value) if isinstance(results, dict) and 'error' in results and results['error']: diff --git a/monkey/infection_monkey/telemetry/base_telem.py b/monkey/infection_monkey/telemetry/base_telem.py index 0adae6d5b..5627cfee1 100644 --- a/monkey/infection_monkey/telemetry/base_telem.py +++ b/monkey/infection_monkey/telemetry/base_telem.py @@ -24,7 +24,7 @@ class BaseTelem(object, metaclass=abc.ABCMeta): """ data = self.get_data() serialized_data = json.dumps(data, cls=self.json_encoder) - self.log_telem_sending(serialized_data, log_data) + self._log_telem_sending(serialized_data, log_data) ControlClient.send_telemetry(self.telem_category, serialized_data) @abc.abstractmethod @@ -38,10 +38,10 @@ class BaseTelem(object, metaclass=abc.ABCMeta): def json_encoder(self): return json.JSONEncoder - def log_telem_sending(self, serialized_data: str, log_data=True): + def _log_telem_sending(self, serialized_data: str, log_data=True): logger.debug(f"Sending {self.telem_category} telemetry.") if log_data: - logger.debug(f"Telemetry contents: {BaseTelem.truncate_data(serialized_data)}") + logger.debug(f"Telemetry contents: {BaseTelem._truncate_data(serialized_data)}") @property @abc.abstractmethod @@ -52,7 +52,7 @@ class BaseTelem(object, metaclass=abc.ABCMeta): pass @staticmethod - def truncate_data(data: str): + def _truncate_data(data: str): if len(data) <= LOGGED_DATA_LENGTH: return data else: diff --git a/monkey/monkey_island/cc/resources/zero_trust/scoutsuite_auth/scoutsuite_auth.py b/monkey/monkey_island/cc/resources/zero_trust/scoutsuite_auth/scoutsuite_auth.py index 3d4cfe013..dbed4dd51 100644 --- a/monkey/monkey_island/cc/resources/zero_trust/scoutsuite_auth/scoutsuite_auth.py +++ b/monkey/monkey_island/cc/resources/zero_trust/scoutsuite_auth/scoutsuite_auth.py @@ -3,7 +3,7 @@ import json import flask_restful from flask import request -from common.cloud.scoutsuite_consts import PROVIDERS +from common.cloud.scoutsuite_consts import CloudProviders from common.utils.exceptions import InvalidAWSKeys from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_auth_service import (is_cloud_authentication_setup, @@ -13,18 +13,18 @@ from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_auth_service imp class ScoutSuiteAuth(flask_restful.Resource): @jwt_required - def get(self, provider: PROVIDERS): - if provider == PROVIDERS.AWS.value: + def get(self, provider: CloudProviders): + if provider == CloudProviders.AWS.value: is_setup, message = is_cloud_authentication_setup(provider) return {'is_setup': is_setup, 'message': message} else: return {'is_setup': False, 'message': ''} @jwt_required - def post(self, provider: PROVIDERS): + def post(self, provider: CloudProviders): key_info = json.loads(request.data) error_msg = '' - if provider == PROVIDERS.AWS.value: + if provider == CloudProviders.AWS.value: try: set_aws_keys(access_key_id=key_info['accessKeyId'], secret_access_key=key_info['secretAccessKey'], diff --git a/monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_auth_service.py b/monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_auth_service.py index 5cc52340d..e5faf3570 100644 --- a/monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_auth_service.py +++ b/monkey/monkey_island/cc/services/zero_trust/scoutsuite/scoutsuite_auth_service.py @@ -3,7 +3,7 @@ import sys from pathlib import PurePath from typing import Tuple -from common.cloud.scoutsuite_consts import PROVIDERS +from common.cloud.scoutsuite_consts import CloudProviders from common.utils.exceptions import InvalidAWSKeys from monkey_island.cc.encryptor import encryptor from monkey_island.cc.services.config import ConfigService @@ -20,8 +20,8 @@ def _add_scoutsuite_to_python_path(): _add_scoutsuite_to_python_path() -def is_cloud_authentication_setup(provider: PROVIDERS) -> Tuple[bool, str]: - if provider == PROVIDERS.AWS.value: +def is_cloud_authentication_setup(provider: CloudProviders) -> Tuple[bool, str]: + if provider == CloudProviders.AWS.value: if is_aws_keys_setup(): return True, "AWS keys already setup. Run Monkey on Island to start the scan." diff --git a/monkey/monkey_island/cc/services/zero_trust/zero_trust_service.py b/monkey/monkey_island/cc/services/zero_trust/zero_trust_service.py index 75af0da0a..09b09689b 100644 --- a/monkey/monkey_island/cc/services/zero_trust/zero_trust_service.py +++ b/monkey/monkey_island/cc/services/zero_trust/zero_trust_service.py @@ -33,8 +33,7 @@ class ZeroTrustService: if pillar in test_info[zero_trust_consts.PILLARS_KEY]: pillar_grade[finding.status] += 1 - pillar_grade[zero_trust_consts.STATUS_UNEXECUTED] = sum(1 for condition in - list(test_unexecuted.values()) if condition) + pillar_grade[zero_trust_consts.STATUS_UNEXECUTED] = list(test_unexecuted.values()).count(True) return pillar_grade