From b48568d9b68a85203e10667b68fb1e92d80ca38e Mon Sep 17 00:00:00 2001 From: Philip Barwikowski Date: Fri, 2 Aug 2019 10:53:18 +0200 Subject: [PATCH 1/2] Use list and add info to finding Use a list of findings and print these at the end. This way they are easier to find if you are going over a large number of files. Also add the match so it is easier to identify false positives --- cred_scanner.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/cred_scanner.py b/cred_scanner.py index e72cdcc..2cbe623 100644 --- a/cred_scanner.py +++ b/cred_scanner.py @@ -7,29 +7,30 @@ @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: print(os.path.join(dirname, subdirname)) # print path to all filenames. - for filename in filenames: - click.echo(os.path.join(dirname, filename)) - f = open(os.path.join(dirname, filename)) - if secret: - pattern = re.compile('(? Date: Fri, 2 Aug 2019 10:54:45 +0200 Subject: [PATCH 2/2] Refactor indentation --- cred_scanner.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cred_scanner.py b/cred_scanner.py index 2cbe623..1284497 100644 --- a/cred_scanner.py +++ b/cred_scanner.py @@ -14,21 +14,21 @@ def scan(path, secret): print(os.path.join(dirname, subdirname)) # print path to all filenames. - for filename in filenames: - click.echo(os.path.join(dirname, filename)) - f = open(os.path.join(dirname, filename)) - if secret: - pattern = re.compile('(? 0: for finding in findings: click.secho(finding, fg='red') sys.exit(1)