diff --git a/cred_scanner.py b/cred_scanner.py index e72cdcc..1284497 100644 --- a/cred_scanner.py +++ b/cred_scanner.py @@ -7,7 +7,7 @@ @click.option('--path', default='.', help='Path other than the local directory to scan') @click.option('--secret', is_flag=True, help='Also look for Secret Key patterns. This may result in many false matches due to the nature of secret keys.') def scan(path, secret): - fail = False + findings = [] for dirname, dirnames, filenames in os.walk(path): # print path to all subdirectories first. for subdirname in dirnames: @@ -24,12 +24,13 @@ def scan(path, secret): try: for i, line in enumerate(f): for match in re.finditer(pattern, line): - click.secho('Found AWS Access Key in ' + os.path.join(dirname, filename,), fg='red') - fail = True + findings.append('Found AWS Access Key in ' + os.path.join(dirname, filename,) + "\n" + str(match)) except UnicodeDecodeError: - click.secho("Can't scan file due to type: " + os.path.join(dirname, filename), fg='red') + click.secho("Can't scan file due to type: " + os.path.join(dirname, filename), fg='yellow') pass - if fail == True: + if len(findings) > 0: + for finding in findings: + click.secho(finding, fg='red') sys.exit(1) if __name__ == "__main__": - scan() \ No newline at end of file + scan()