-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from dmdhrumilmistry/issue-37
Add features as described in Issue 37
- Loading branch information
Showing
5 changed files
with
100 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ logs/ | |
book | ||
src | ||
stacks | ||
docker/configs | ||
docker/configs | ||
.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,58 @@ | ||
import logging | ||
from mantis.db.crud_assets import read_assets | ||
|
||
|
||
async def get_orgs(): | ||
pipeline = [] | ||
|
||
pipeline.extend([ | ||
{"$group": { | ||
"_id" : None, | ||
"orgs":{ | ||
"$addToSet": "$org" | ||
} | ||
} | ||
} | ||
]) | ||
pipeline.extend([{"$group": {"_id": None, "orgs": {"$addToSet": "$org"}}}]) | ||
orgs = await read_assets(pipeline) | ||
|
||
if orgs: | ||
return orgs[0]["orgs"] | ||
|
||
else: | ||
return None | ||
return None | ||
|
||
|
||
async def get_domains(orgs:list[str], asset_types:list[str], after_filter:str, before_filter:str): | ||
if len(orgs) == 0: | ||
logging.warning('No orgs selected') | ||
return [] | ||
|
||
if len(asset_types) == 0: | ||
logging.warning('no asset type was selected') | ||
return [] | ||
|
||
match_filter = { | ||
"org": {"$in": orgs}, | ||
"asset_type": {"$in": asset_types}, | ||
} | ||
|
||
if after_filter: | ||
match_filter.setdefault("created_timestamp", {}) | ||
match_filter["created_timestamp"]["$gte"] = after_filter | ||
|
||
if before_filter: | ||
match_filter.setdefault("created_timestamp", {}) | ||
match_filter["created_timestamp"]["$lte"] = before_filter | ||
|
||
pipeline = [ | ||
{ | ||
"$match": match_filter | ||
}, | ||
{ | ||
"$group": { | ||
"_id": None, | ||
"asset": {"$addToSet": "$asset"}, | ||
}, | ||
}, | ||
] | ||
|
||
result = await read_assets(pipeline) | ||
domains = [] | ||
if result and len(result) > 0: | ||
domains = result[0].get('asset', []) | ||
else: | ||
logging.warning('No match found') | ||
return domains |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
import logging | ||
from mantis.models.args_model import ArgsModel | ||
from mantis.utils.list_subcommand_utils import get_orgs | ||
from mantis.utils.list_subcommand_utils import get_orgs, get_domains | ||
|
||
|
||
class ListWorkflow: | ||
|
||
@staticmethod | ||
async def executor(args: ArgsModel): | ||
|
||
if args.list_orgs: | ||
logging.info("Getting orgs from database") | ||
orgs = await get_orgs() | ||
print() | ||
print(f'''Total Number of orgs onboarded: {len(orgs)}''') | ||
print() | ||
for org in orgs: | ||
print(org) | ||
if orgs: | ||
print(f"\nTotal Number of orgs onboarded: {len(orgs)}\n") | ||
print("\n".join(orgs)) | ||
else: | ||
logging.info("No orgs found in database") | ||
|
||
if args.list_domains: | ||
logging.info("Getting subdomains from database") | ||
domains = await get_domains(args.orgs_list, args.asset_types_list, args.after_datetime_filter, args.before_datetime_filter) | ||
if domains: | ||
print(f"\nOrgs Filter: {','.join(args.orgs_list)}") | ||
print(f"Total Domains Found based on provided filters: {len(domains)}\n") | ||
print('\n'.join(domains)) | ||
else: | ||
logging.info("No domains found") |