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

Refactor file hierarchy #326

Merged
merged 7 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The following cloud providers are currently supported/planned:
Install via `pip`:

$ pip install scoutsuite
$ scout --help

Install from source:

Expand All @@ -48,7 +49,7 @@ Install from source:
$ virtualenv -p python3 venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python Scout.py --help
$ python scout.py --help

## Requirements

Expand Down
44 changes: 0 additions & 44 deletions Scout.py

This file was deleted.

36 changes: 35 additions & 1 deletion ScoutSuite/scout.py → ScoutSuite/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,52 @@

from concurrent.futures import ThreadPoolExecutor

from ScoutSuite.output.report_file import ReportFile
from ScoutSuite.core.cli_parser import ScoutSuiteArgumentParser
from ScoutSuite.core.console import set_config_debug_level, print_info, print_exception
from ScoutSuite.core.exceptions import RuleExceptions
from ScoutSuite.core.processingengine import ProcessingEngine
from ScoutSuite.core.ruleset import Ruleset
from ScoutSuite.core.server import Server
from ScoutSuite.output.html import ScoutReport
from ScoutSuite.output.report_file import ReportFile
from ScoutSuite.output.utils import get_filename
from ScoutSuite.providers import get_provider
from ScoutSuite.providers.base.authentication_strategy_factory import get_authentication_strategy


def run_from_cli():
parser = ScoutSuiteArgumentParser()
args = parser.parse_args()

# Get the dictionary to get None instead of a crash
args = args.__dict__

run(args.get('provider'),
args.get('profile'),
args.get('user_account'), args.get('service_account'),
args.get('cli'), args.get('msi'), args.get('service_principal'), args.get('file_auth'), args.get('tenant_id'),
args.get('subscription_id'),
args.get('client_id'), args.get('client_secret'),
args.get('username'), args.get('password'),
args.get('project_id'), args.get('folder_id'), args.get('organization_id'), args.get('all_projects'),
args.get('report_name'), args.get('report_dir'),
args.get('timestamp'),
args.get('services'), args.get('skipped_services'),
args.get('thread_config'), # todo deprecate
args.get('result_format'),
args.get('database_name'),
args.get('host_ip'),
args.get('host_port'),
args.get('max_workers'),
args.get('regions'),
args.get('fetch_local'), args.get('update'),
args.get('ip_ranges'), args.get('ip_ranges_name_key'),
args.get('ruleset'), args.get('exceptions'),
args.get('force_write'),
args.get('debug'),
args.get('no_browser'))


def run(provider,
profile,
user_account, service_account,
Expand Down
8 changes: 8 additions & 0 deletions scout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python

import sys

from ScoutSuite.__main__ import run_from_cli

if __name__ == "__main__":
sys.exit(run_from_cli())
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
url='https://github.com/nccgroup/ScoutSuite',
entry_points={
'console_scripts': [
'Scout = ScoutSuite.__main__:main',
'scout = ScoutSuite.__main__:run_from_cli',
]
},
packages=find_packages(),
Expand Down
16 changes: 8 additions & 8 deletions tests/test-main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from mock import MagicMock, patch

from Scout import main
from ScoutSuite.__main__ import run_from_cli
from ScoutSuite.core.cli_parser import ScoutSuiteArgumentParser


Expand All @@ -25,7 +25,7 @@ def setUp(self):
("ProcessingEngine", self.mocked_engine),
("ScoutReport", self.mocked_report),
("webbrowser", self.mocked_browser)]:
constructor_obj = patch("ScoutSuite.scout.%s" % import_name, return_value=mocked_object).start()
constructor_obj = patch("ScoutSuite.__main__.%s" % import_name, return_value=mocked_object).start()
self.constructor[mocked_object] = constructor_obj

self.mocked_report.save = MagicMock(return_value="dummyfile")
Expand All @@ -40,7 +40,7 @@ async def test_empty(self):
with patch("sys.stderr", return_value=MagicMock()):
with self.assertRaises(SystemExit):
args = ScoutSuiteArgumentParser().parse_args(args)
code = await main(args)
code = await run_from_cli(args)

assert (code is None)

Expand All @@ -49,7 +49,7 @@ async def test_aws_provider(self):
self.mocked_provider.provider_code = "aws"

args = ScoutSuiteArgumentParser().parse_args(args)
code = await main(args)
code = await run_from_cli(args)

success_code = 0
assert (code == success_code)
Expand All @@ -64,7 +64,7 @@ async def test_gcp_provider(self):
self.mocked_provider.provider_code = "gcp"

args = ScoutSuiteArgumentParser().parse_args(args)
code = await main(args)
code = await run_from_cli(args)

success_code = 0
assert (code == success_code)
Expand All @@ -79,7 +79,7 @@ async def test_azure_provider(self):
self.mocked_provider.provider_code = "azure"

args = ScoutSuiteArgumentParser().parse_args(args)
code = await main(args)
code = await run_from_cli(args)

success_code = 0
assert (code == success_code)
Expand All @@ -95,7 +95,7 @@ async def test_unauthenticated(self):
self.mocked_provider.authenticate = MagicMock(return_value=False)

args = ScoutSuiteArgumentParser().parse_args(args)
code = await main(args)
code = await run_from_cli(args)

unauthenticated_code = 42
assert (code == unauthenticated_code)
Expand All @@ -110,7 +110,7 @@ def _raise(e):
self.mocked_provider.fetch = MagicMock(side_effect=_raise(KeyboardInterrupt))

args = ScoutSuiteArgumentParser().parse_args(args)
code = await main(args)
code = await run_from_cli(args)

keyboardinterrupted_code = 130
assert (code == keyboardinterrupted_code)
8 changes: 4 additions & 4 deletions tests/test-scoutsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import mock

from nose.plugins.attrib import attr
from Scout import main
from ScoutSuite.__main__ import run_from_cli
from ScoutSuite.core.console import set_config_debug_level


Expand All @@ -15,7 +15,7 @@ def setUpClass(cls):

@staticmethod
def call_scout_suite(args):
args = ['./Scout.py'] + args
args = ['./scout.py'] + args

args.append('aws')

Expand All @@ -33,13 +33,13 @@ def call_scout_suite(args):

sys = None
with mock.patch.object(sys, 'argv', args):
return main()
return run_from_cli()

#
# Make sure that ScoutSuite does not crash with --help
#
def test_scout_suite_help(self):
command = './Scout.py --help'
command = './scout.py --help'
process = subprocess.Popen(command, shell=True, stdout=None)
process.wait()
assert process.returncode == 0
Expand Down