Skip to content

Commit

Permalink
add logs to console while validation (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: daknhh <[email protected]>
  • Loading branch information
daknhh and daknhh authored May 19, 2023
1 parent 9a16931 commit c996d50
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions scpkit/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""SCPkit
Usage:
main.py (validate | merge) [--sourcefiles sourcefiles] [--profile profile] [ --outdir outdir] [--validate-after-merge] [--readable]
main.py (validate | merge) [--sourcefiles sourcefiles] [--profile profile] [ --outdir outdir] [--validate-after-merge] [--readable] [--console]
Options:
-h --help Show this screen.
Expand All @@ -10,6 +10,7 @@
--profile profile AWS profile name
--validate-after-merge Validate the policies after merging them
--readable Leave indentation and some whitespace to make the SCPs readable
--console Adds Log to console
"""
from docopt import docopt
from .src.validate import validate_policies
Expand All @@ -27,7 +28,7 @@ def main():
scp_merge(**arguments)

if arguments.get("validate"):
validate_policies(arguments['scps'], arguments['profile'], arguments['outdir'])
validate_policies(arguments['scps'], arguments['profile'], arguments['outdir'], arguments['console'])


if __name__ == '__main__':
Expand Down
12 changes: 11 additions & 1 deletion scpkit/src/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create_client(session, service):
return session.client(service)


def validate_policies(scps, profile, outdir=None):
def validate_policies(scps, profile, outdir=None, console=False):
"""Validates SCPs
Args:
Expand All @@ -38,9 +38,19 @@ def validate_policies(scps, profile, outdir=None):
access_analyzer = create_client(create_session(profile), "accessanalyzer")

for scp in scps:
if(console):
print(f"🧪 Validate SCP: {scp.name}")
scp.validate(access_analyzer)
if scp.findings:
if(console):
print(f" 🚨 Error(s) in {scp.name}:")
for finding in scp.findings:
print(f" {finding['issueCode']} - {finding['findingDetails']}")
if outdir:
scp.write_findings_for_scp(outdir)
if(console):
print(" ℹ️ More details check log file {outdir}/{scp.name}-findings.json")
else:
print(scp.findings_json)
if(console):
print(f" ℹ️ More details check log file ./{scp.name}-findings.json")

0 comments on commit c996d50

Please sign in to comment.