Skip to content

Commit 8ddd312

Browse files
author
Kinnaird McQuade
committed
Fixes links to the inline policies in case there are duplicate names. Fixes #63
1 parent 1f43d8c commit 8ddd312

File tree

6 files changed

+526
-141
lines changed

6 files changed

+526
-141
lines changed

cloudsplaining/command/scan.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,25 @@ def scan(
8383
with open(input) as f:
8484
contents = f.read()
8585
account_authorization_details_cfg = json.loads(contents)
86-
scan_account_authorization_details(
86+
rendered_html_report = scan_account_authorization_details(
8787
account_authorization_details_cfg, exclusions, account_name, output, write_data_files=True
8888
)
89+
html_output_file = os.path.join(output, f"iam-report-{account_name}.html")
90+
logger.info("Saving the report to %s", html_output_file)
91+
if os.path.exists(html_output_file):
92+
os.remove(html_output_file)
93+
94+
with open(html_output_file, "w") as f:
95+
f.write(rendered_html_report)
96+
97+
print(f"Wrote HTML results to: {html_output_file}")
98+
99+
# Open the report by default
100+
if not skip_open_report:
101+
print("Opening the HTML report")
102+
url = "file://%s" % os.path.abspath(html_output_file)
103+
webbrowser.open(url, new=2)
104+
89105
if os.path.isdir(input):
90106
logger.info(
91107
"The path given is a directory. Scanning for account authorization files and generating report."
@@ -103,6 +119,9 @@ def scan(
103119
account_authorization_details_cfg, exclusions, account_name, output, write_data_files=True
104120
)
105121
html_output_file = os.path.join(output, f"iam-report-{account_name}.html")
122+
logger.info("Saving the report to %s", html_output_file)
123+
if os.path.exists(html_output_file):
124+
os.remove(html_output_file)
106125

107126
with open(html_output_file, "w") as f:
108127
f.write(rendered_html_report)

cloudsplaining/output/templates/analysis/finding-card/names.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="card">
2-
<h6 class="card-header" id="{{ finding['PolicyName'] }}">
2+
<h6 class="card-header" id="{{ finding['PolicyName'] }}{% if finding['AttachedToPrincipal'] %}{{ finding['AttachedToPrincipal'] }}{% endif %}">
33
Name: {{ finding["PolicyName"] }}
44
<br>
55
<br>

cloudsplaining/output/templates/summary/aws-managed.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{% if finding["ManagedBy"] == "AWS" %}
3232
<tr>
3333
<td></td>
34-
<td><a href="#{{ finding['PolicyName'] }}">{{ finding['PolicyName'] }}</a></td>
34+
<td><a href="#{{ finding['PolicyName'] }}{% if finding['AttachedToPrincipal'] %}{{ finding['AttachedToPrincipal'] }}{% endif %}">{{ finding['PolicyName'] }}</a></td>
3535
<td>{{ finding["ServicesCount"] }}</td>
3636
<td><p style="max-height: 100px; overflow: scroll;">{% for service in finding["Services"] %}{{ service }}{% if not loop.last %}, {% endif %}{% endfor %}</p></td>
3737
<td>{{ finding["ActionsCount"] }}</td>

cloudsplaining/output/templates/summary/customer-managed.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<tr>
4040
<td></td>
4141
<td>{% if finding["Type"] == "Policy" %}{{ finding["ManagedBy"] }}-Managed {{ finding["Type"] }}{% else %}Inline {{ finding["Type"] }} Policy{% endif %}</td>
42-
<td><a href="#{{ finding['PolicyName'] }}">{{ finding['PolicyName'] }}</a></td>
42+
<td><a href="#{{ finding['PolicyName'] }}{% if finding['AttachedToPrincipal'] %}{{ finding['AttachedToPrincipal'] }}{% endif %}">{{ finding['PolicyName'] }}</a></td>
4343
<td>{% if finding["Type"] == "Policy" %}{% else %}{{ finding['Name'] }}{% endif %}</td>
4444
<td>{{ finding["ServicesCount"] }}</td>
4545
<td><p style="max-height: 100px; overflow: scroll;">{% for service in finding["Services"] %}{{ service }}{% if not loop.last %}, {% endif %}{% endfor %}</p></td>

0 commit comments

Comments
 (0)