Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to extract the Report yaml block in python dictionary format #60

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions configs/local.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Do not store sensitive information and check-in code to gitlab

report:
title: "Attack Surface Management Report"
author: "John Doe"
date: "2024-09-30"
header: "Confidential - For Internal Use Only"
footer: "Company XYZ - All Rights Reserved"
format: "pdf"

workflow:
- workflowName: 'default'
schedule: 'daily between 00:00 and 04:00'
Expand Down
22 changes: 22 additions & 0 deletions mantis/config_parsers/config_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ def convert_yml_to_obj(yml_file_path):
logging.error('(convert_yml_to_obj) Error in reading yml file: {}, Reason: {}'.format(yml_file_path, e))
sys.exit(0)


@staticmethod
def convert_yml_to_dict(yml_file_path):
config = dict()
try:
with open(yml_file_path, 'r') as yml_file:
yml_to_dict = yaml.load(yml_file, Loader=yaml.SafeLoader)
config.update(yml_to_dict)
ConfigProvider.yml_config = config
except yaml.YAMLError as e:
logging.error('(convert_yml_to_obj) Error in reading yml file: {}, Reason: {}'.format(yml_file_path, e))
sys.exit(0)
except OSError as e:
logging.error('(convert_yml_to_obj) Error in reading yml file: {}, Reason: {}'.format(yml_file_path, e))
sys.exit(0)


@staticmethod
def get_local_config():
Expand All @@ -40,3 +56,9 @@ def get_config():
else:
ConfigProvider.get_local_config()
return ConfigProvider.yml_config

@staticmethod
def get_report():
config_path = os.path.join('configs', 'local.yml')
ConfigProvider.convert_yml_to_dict(config_path)
return ConfigProvider.yml_config.get("report")
1 change: 1 addition & 0 deletions mantis/models/args_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ class ArgsModel(BaseModel):
subdomain: str = Field(None)
list_: bool = False
list_orgs: bool = False
report_: bool = False
in_scope: bool = False

19 changes: 18 additions & 1 deletion mantis/utils/args_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def list_msg(name=None):

\033[0;32mmantis list {subcommand}\033[0m
'''

@staticmethod
def report_msg(name=None):
return '''
\033[1;34mREPORT:\033[0m

\033[0;32mmantis report -o example_org\033[0m
'''

@staticmethod
def args_parse() -> ArgsModel:
Expand Down Expand Up @@ -235,7 +243,13 @@ def args_parse() -> ArgsModel:
help = 'List only the records from nameserver that are in scope',
action = 'store_true'
)

report_parser = subparser.add_parser("report", help="Generate report", usage=ArgsParse.report_msg())

report_parser.add_argument('-o', '--org',
dest = 'org',
required = True,
help = "name of the organisation")

list_parser = subparser.add_parser("list", help="List entities present in db", usage=ArgsParse.list_msg())

Expand All @@ -259,7 +273,7 @@ def args_parse() -> ArgsModel:
parsed_args['input_type'] = "file"
parsed_args['input'] = str(args.file_name)

if args.subcommand != "list":
if args.subcommand != "list" and args.subcommand != "report":

if args.aws_profiles:
parsed_args["aws_profiles"] = args.aws_profiles.split(',')
Expand Down Expand Up @@ -314,6 +328,9 @@ def args_parse() -> ArgsModel:
if args.list_sub_command == "orgs":
parsed_args["list_orgs"] = True

if args.subcommand == "report":
parsed_args["report_"] = True

args_pydantic_obj = ArgsModel.parse_obj(parsed_args)
logging.info(f'parsed args - {args_pydantic_obj}')
logging.info(f"Parsing Arguements - Completed")
Expand Down
5 changes: 5 additions & 0 deletions mantis/utils/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ def is_scanNewOnly_tool(tool_name, args):
return False
else:
return True

@staticmethod
def get_report_dict():
report = ConfigProvider.get_report()
return report
3 changes: 3 additions & 0 deletions mantis/workflows/mantis_workflow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mantis.models.args_model import ArgsModel
from mantis.modules.workflow import Workflow
from mantis.workflows.list_workflow import ListWorkflow
from mantis.workflows.report_workflow import ReportWorkflow
import asyncio

class MantisWorkflow:
Expand All @@ -9,6 +10,8 @@ def select_workflow(args: ArgsModel) -> None:

if args.list_:
asyncio.run(ListWorkflow.executor(args))
elif args.report_:
asyncio.run(ReportWorkflow.executor())
else:
asyncio.run(Workflow.workflow_executor(args))

12 changes: 12 additions & 0 deletions mantis/workflows/report_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import logging
from mantis.utils.config_utils import ConfigUtils

class ReportWorkflow:

@staticmethod
async def executor():

report = ConfigUtils.get_report_dict()

logging.info("Generating report yaml block as dictionary")
print(f"Report: {report}")
5 changes: 4 additions & 1 deletion setup/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
services:
mantis:
image: ghcr.io/phonepe/mantis:latest
#image: ghcr.io/phonepe/mantis:latest
build:
dockerfile: Dockerfile
context: ../../
container_name: mantis
restart: on-failure
command: sleep infinity
Expand Down