-
Notifications
You must be signed in to change notification settings - Fork 100
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
Improved Indentation and added Comments in the codebase. #133
Changes from all commits
2e8203e
683d054
501f484
8c12675
713da7a
9ba1b1a
68dfa0d
3dbcd93
e01d2eb
e618fdc
6caf26f
664d4ec
0e9cdd7
ac36b02
8ffc0aa
f8ae001
bace7b1
6db5dda
d968ac3
4a38f67
63f8e58
61fe0e4
0fe183b
8455a4e
3618b77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,8 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Import the scanner module from the gcp_scanner package | ||
from src.gcp_scanner import scanner | ||
scanner.main() | ||
|
||
# Call the main function of the scanner module to start the scanning process | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant |
||
scanner.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,10 @@ | |
|
||
""" | ||
|
||
# Importing the scanner module | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant |
||
from . import scanner | ||
|
||
# Checking if the code is running as the main module | ||
if __name__ == '__main__': | ||
# Calling the main function of the scanner module | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant |
||
scanner.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
import argparse | ||
import logging | ||
|
||
|
||
# Define a function to create an argument parser using the argparse module | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant |
||
def arg_parser(): | ||
"""Creates an argument parser using the `argparse` module and defines | ||
several command-line arguments. | ||
|
@@ -31,102 +33,117 @@ def arg_parser(): | |
argparse.Namespace: A namespace object containing the parsed command-line | ||
arguments. | ||
""" | ||
# Create a new parser object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant. I am stopping on this one. You do not need to comment obvious sections of the code. |
||
parser = argparse.ArgumentParser( | ||
prog='scanner.py', | ||
description='GCP Scanner', | ||
usage='python3 %(prog)s -o folder_to_save_results -g -') | ||
prog='scanner.py', # program name | ||
description='GCP Scanner', # description | ||
usage='python3 %(prog)s -o folder_to_save_results -g -' | ||
) | ||
|
||
# Define a required argument group | ||
required_named = parser.add_argument_group('Required parameters') | ||
# Add a required argument to the group | ||
required_named.add_argument( | ||
'-o', | ||
'--output-dir', | ||
required=True, | ||
dest='output', | ||
default='scan_db', | ||
help='Path to output directory') | ||
'-o', # short option name | ||
'--output-dir', # long option name | ||
required=True, | ||
dest='output', | ||
default='scan_db', | ||
help='Path to output directory' | ||
) | ||
|
||
# Add command line arguments to the parser object | ||
parser.add_argument( | ||
'-k', | ||
'--sa-key-path', | ||
default=None, | ||
dest='key_path', | ||
help='Path to directory with SA keys in json format') | ||
'-k', | ||
'--sa-key-path', | ||
default=None, # Default value if option is not specified | ||
dest='key_path', | ||
help='Path to directory with SA keys in json format' # Help message | ||
) | ||
parser.add_argument( | ||
'-g', | ||
'--gcloud-profile-path', | ||
default=None, | ||
dest='gcloud_profile_path', | ||
help='Path to directory with gcloud profile. Specify -\ | ||
to search for credentials in default gcloud config path' | ||
'-g', | ||
'--gcloud-profile-path', | ||
default=None, | ||
dest='gcloud_profile_path', | ||
help='Path to directory with gcloud profile. Specify - to search for\ | ||
credentials in default gcloud config path' | ||
) | ||
parser.add_argument( | ||
'-m', | ||
'--use-metadata', | ||
default=False, | ||
dest='use_metadata', | ||
action='store_true', | ||
help='Extract credentials from GCE instance metadata') | ||
'-m', | ||
'--use-metadata', | ||
default=False, | ||
dest='use_metadata', | ||
action='store_true', | ||
help='Extract credentials from GCE instance metadata' | ||
) | ||
parser.add_argument( | ||
'-at', | ||
'--access-token-files', | ||
default=None, | ||
dest='access_token_files', | ||
help='A list of comma separated files with access token and OAuth scopes.\ | ||
TTL limited. A token and scopes should be stored in JSON format.') | ||
'-at', | ||
'--access-token-files', | ||
default=None, | ||
dest='access_token_files', | ||
help='A list of comma separated files with access token and OAuth scopes\ | ||
TTL limited. A token and scopes should be stored in JSON format.' | ||
) | ||
parser.add_argument( | ||
'-rt', | ||
'--refresh-token-files', | ||
default=None, | ||
dest='refresh_token_files', | ||
help='A list of comma separated files with refresh_token, client_id,\ | ||
token_uri and client_secret stored in JSON format.' | ||
'-rt', | ||
'--refresh-token-files', | ||
default=None, | ||
dest='refresh_token_files', | ||
help='A list of comma separated files with refresh_token, client_id,\ | ||
token_uri and client_secret stored in JSON format.' | ||
) | ||
|
||
parser.add_argument( | ||
'-s', | ||
'--service-account', | ||
default=None, | ||
dest='key_name', | ||
help='Name of individual SA to scan') | ||
'-s', | ||
'--service-account', | ||
default=None, | ||
dest='key_name', | ||
help='Name of individual SA to scan') | ||
parser.add_argument( | ||
'-p', | ||
'--project', | ||
default=None, | ||
dest='target_project', | ||
help='Name of individual project to scan') | ||
'-p', | ||
'--project', | ||
default=None, | ||
dest='target_project', | ||
help='Name of individual project to scan') | ||
parser.add_argument( | ||
'-f', | ||
'--force-projects', | ||
default=None, | ||
dest='force_projects', | ||
help='Comma separated list of project names to include in the scan') | ||
'-f', | ||
'--force-projects', | ||
default=None, | ||
dest='force_projects', | ||
help='Comma separated list of project names to include in the scan') | ||
parser.add_argument( | ||
'-c', | ||
'--config', | ||
default=None, | ||
dest='config_path', | ||
help='A path to config file with a set of specific resources to scan.') | ||
'-c', | ||
'--config', | ||
default=None, | ||
dest='config_path', | ||
help='A path to config file with a set of specific resources to scan.') | ||
parser.add_argument( | ||
'-l', | ||
'--logging', | ||
default='WARNING', | ||
dest='log_level', | ||
choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'), | ||
help='Set logging level (INFO, WARNING, ERROR)') | ||
'-l', | ||
'--logging', | ||
default='WARNING', | ||
dest='log_level', | ||
choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'), | ||
help='Set logging level (INFO, WARNING, ERROR)') | ||
parser.add_argument( | ||
'-lf', | ||
'--log-file', | ||
default=None, | ||
dest='log_file', | ||
help='Save logs to the path specified rather than displaying in\ | ||
console') | ||
'-lf', | ||
'--log-file', | ||
default=None, | ||
dest='log_file', | ||
help='Save logs to the path specified rather than displaying in\ | ||
console') | ||
|
||
# Parse the command line arguments | ||
args: argparse.Namespace = parser.parse_args() | ||
|
||
# Check if none of the necessary options are selected | ||
if not args.key_path and not args.gcloud_profile_path \ | ||
and not args.use_metadata and not args.access_token_files\ | ||
and not args.refresh_token_files: | ||
and not args.use_metadata and not args.access_token_files\ | ||
and not args.refresh_token_files: | ||
|
||
# If none of the options are selected, log an error message | ||
logging.error( | ||
'Please select at least one option to begin scan\ | ||
-k/--sa-key-path,-g/--gcloud-profile-path, -m, -rt, -at' | ||
) | ||
-k/--sa-key-path,-g/--gcloud-profile-path, -m, -rt, -at') | ||
|
||
# Return the parsed command line arguments | ||
return args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant