Renamed cloud providers enum to camel case

This commit is contained in:
VakarisZ 2021-01-04 15:46:53 +02:00
parent 8cd3834fe4
commit eaf9b6a8d1
7 changed files with 18 additions and 19 deletions

View File

@ -1,7 +1,7 @@
from enum import Enum
class PROVIDERS(Enum):
class CloudProviders(Enum):
AWS = 'aws'
AZURE = 'azure'
GCP = 'gcp'

View File

@ -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()

View File

@ -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']:

View File

@ -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:

View File

@ -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'],

View File

@ -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."

View File

@ -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