Merge pull request #550 from shreyamalviya/emptyconfigfields

Remove `None` values from list of networks to scan
This commit is contained in:
VakarisZ 2020-03-06 08:30:01 +02:00 committed by GitHub
commit 4460f853e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -44,9 +44,9 @@ class NetworkRange(object, metaclass=ABCMeta):
@staticmethod
def get_range_obj(address_str):
address_str = address_str.strip()
if not address_str: # Empty string
return None
address_str = address_str.strip()
if NetworkRange.check_if_range(address_str):
return IpRange(ip_range=address_str)
if -1 != address_str.find('/'):

View File

@ -153,9 +153,18 @@ class ConfigService:
def ssh_key_exists(keys, user, ip):
return [key for key in keys if key['user'] == user and key['ip'] == ip]
def _filter_none_values(data):
if isinstance(data, dict):
return {k: ConfigService._filter_none_values(v) for k, v in data.items() if k is not None and v is not None}
elif isinstance(data, list):
return [ConfigService._filter_none_values(item) for item in data if item is not None]
else:
return data
@staticmethod
def update_config(config_json, should_encrypt):
# PBA file upload happens on pba_file_upload endpoint and corresponding config options are set there
config_json = ConfigService._filter_none_values(config_json)
monkey_island.cc.services.post_breach_files.set_config_PBA_files(config_json)
if should_encrypt:
try: