Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cred_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
scan()