Skip to content

Commit 92562eb

Browse files
mrpool404kmcquade
andauthored
Ability to return json results when used as python lib (#250)
* Modified 'scan_account_authorization_details' in '/cloudsplaining/command/scan,oy' to return raw json results along with rendered_html report string. Also added a parameter 'return_json_results' to the function to make it backward compatible. Returning json along can be helpful in programatically analysing results and taking further actions when used as python library. * Update the typo in return type of scan_account_authorization * Update README.md Co-authored-by: Kinnaird McQuade <[email protected]>
1 parent 6d525b1 commit 92562eb

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,4 @@ Try upgrading to the latest version of Cloudsplaining. This error was fixed in v
381381
* [AWS Privilege Escalation Methods](https://github.com/RhinoSecurityLabs/AWS-IAM-Privilege-Escalation) by [Spencer Gietzen](https://twitter.com/SpenGietz) at Rhino Security Labs
382382
* [Understanding Access Level Summaries within Policy Summaries](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_understand-policy-summary-access-level-summaries.html)
383383
* [Leveraging next-generation blockchain-based AI across multiple service meshes to transparently automate multi-cloud IAM wizardry :mage_man:](http://kmcquade.com/rick.html)
384+

cloudsplaining/command/scan.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def scan_account_authorization_details(
137137
output_directory: str = os.getcwd(),
138138
write_data_files: bool = False,
139139
minimize: bool = False,
140-
) -> str: # pragma: no cover
140+
return_json_results: bool = False
141+
) -> Any: # pragma: no cover
141142
"""
142143
Given the path to account authorization details files and the exclusions config file, scan all inline and
143144
managed policies in the account to identify actions that do not leverage resource constraints.
@@ -187,7 +188,14 @@ def scan_account_authorization_details(
187188
findings_data_filepath = write_results_data_file(results, findings_data_file)
188189
print(f"Findings data file saved: {findings_data_filepath}")
189190

190-
return rendered_report
191+
if return_json_results:
192+
return {
193+
"iam_results" : authorization_details.results,
194+
"iam_findings" : results,
195+
"rendered_report" : rendered_report
196+
}
197+
else:
198+
return rendered_report
191199

192200

193201
def get_authorization_files_in_directory(

0 commit comments

Comments
 (0)