forked from p15670423/monkey
Small ScoutSuite feature code style refactorings
This commit is contained in:
parent
e79290e761
commit
85f4c4f250
|
@ -36,3 +36,7 @@ class NoInternetError(Exception):
|
||||||
|
|
||||||
class ScoutSuiteScanError(Exception):
|
class ScoutSuiteScanError(Exception):
|
||||||
""" Raise to indicate problems ScoutSuite encountered during scanning"""
|
""" Raise to indicate problems ScoutSuite encountered during scanning"""
|
||||||
|
|
||||||
|
|
||||||
|
class UnknownFindingError(Exception):
|
||||||
|
""" Raise when provided finding is of unknown type"""
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from common.common_consts import zero_trust_consts
|
from common.common_consts import zero_trust_consts
|
||||||
|
from common.utils.exceptions import UnknownFindingError
|
||||||
from monkey_island.cc.models.zero_trust.finding import Finding
|
from monkey_island.cc.models.zero_trust.finding import Finding
|
||||||
from monkey_island.cc.services.zero_trust.monkey_details_service import MonkeyDetailsService
|
from monkey_island.cc.services.zero_trust.monkey_details_service import MonkeyDetailsService
|
||||||
|
|
||||||
|
@ -10,19 +11,20 @@ class FindingService:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_findings() -> List[Finding]:
|
def get_all_findings() -> List[Finding]:
|
||||||
findings = list(Finding.objects)
|
findings = list(Finding.objects)
|
||||||
details = []
|
|
||||||
for i in range(len(findings)):
|
for i in range(len(findings)):
|
||||||
if findings[i].finding_type == zero_trust_consts.MONKEY_FINDING:
|
if findings[i].finding_type == zero_trust_consts.MONKEY_FINDING:
|
||||||
details = MonkeyDetailsService.fetch_details_for_display(findings[i].details.id)
|
details = MonkeyDetailsService.fetch_details_for_display(findings[i].details.id)
|
||||||
elif findings[i].finding_type == zero_trust_consts.SCOUTSUITE_FINDING:
|
elif findings[i].finding_type == zero_trust_consts.SCOUTSUITE_FINDING:
|
||||||
details = findings[i].details.fetch().to_mongo()
|
details = findings[i].details.fetch().to_mongo()
|
||||||
|
else:
|
||||||
|
raise UnknownFindingError(f"Unknown finding type {findings[i].finding_type}")
|
||||||
findings[i] = findings[i].to_mongo()
|
findings[i] = findings[i].to_mongo()
|
||||||
findings[i] = FindingService.get_enriched_finding(findings[i])
|
findings[i] = FindingService._get_enriched_finding(findings[i])
|
||||||
findings[i]['details'] = details
|
findings[i]['details'] = details
|
||||||
return findings
|
return findings
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_enriched_finding(finding):
|
def _get_enriched_finding(finding):
|
||||||
test_info = zero_trust_consts.TESTS_MAP[finding['test']]
|
test_info = zero_trust_consts.TESTS_MAP[finding['test']]
|
||||||
enriched_finding = {
|
enriched_finding = {
|
||||||
'finding_id': str(finding['_id']),
|
'finding_id': str(finding['_id']),
|
||||||
|
|
|
@ -12,7 +12,7 @@ EVENT_FETCH_CNT = 50
|
||||||
class MonkeyDetailsService:
|
class MonkeyDetailsService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fetch_details_for_display(finding_id: ObjectId):
|
def fetch_details_for_display(finding_id: ObjectId) -> dict:
|
||||||
pipeline = [{'$match': {'_id': finding_id}},
|
pipeline = [{'$match': {'_id': finding_id}},
|
||||||
{'$addFields': {'oldest_events': {'$slice': ['$events', EVENT_FETCH_CNT]},
|
{'$addFields': {'oldest_events': {'$slice': ['$events', EVENT_FETCH_CNT]},
|
||||||
'latest_events': {'$slice': ['$events', -1 * EVENT_FETCH_CNT]},
|
'latest_events': {'$slice': ['$events', -1 * EVENT_FETCH_CNT]},
|
||||||
|
|
Loading…
Reference in New Issue