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

Update configs and error handling #4

Merged
merged 1 commit into from
Jul 18, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions IAMActionHunter/IAMActionHunter.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,26 @@ def main():

if args.config:
# Try to load config from builtin configs
if args.config in vars(configs):
query_config = vars(configs)[args.config]
builtin_configs = vars(configs)
if args.config in builtin_configs:
query_config = builtin_configs[args.config]
else:
# Else try to load a config file
try:
with open(f"configs/{args.config}.json", "r") as f:
with open(f"{args.config}", "r") as f:
query_config = json.loads(f.read())
except FileNotFoundError:
try:
with open(args.config, "r") as f:
query_config = json.loads(f.read())
except FileNotFoundError:
print(f"{args.config} does not exist. Please specify a valid config file or name")
sys.exit(1)
print(f"{args.config} does not exist. Please specify a valid config file or name. ")
print("Builtin config options are:")
print()
for config in builtin_configs:
if not config.startswith("__"):
print(config)
print()
sys.exit(1)
except json.decoder.JSONDecodeError:
print(f"{args.config} is not a valid config JSON file")
sys.exit(1)

# Iterate through all files and process them
for permission_file in all_files:
Expand Down
8 changes: 8 additions & 0 deletions IAMActionHunter/configs/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,12 @@
],
"AllOrNone": True,
},
{
"Description": "",
"Name": "ModifyEC2UserData",
"ActionsNeeded": [
"ec2:ModifyInstanceAttribute",
],
"AllOrNone": True,
},
]