forked from bridgecrewio/detect-secrets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aaron Loo
committed
Nov 9, 2020
1 parent
9aaae64
commit 2d300cb
Showing
34 changed files
with
134 additions
and
770 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +0,0 @@ | ||
import hashlib | ||
import os | ||
import subprocess | ||
|
||
|
||
def build_automaton(word_list): | ||
""" | ||
:type word_list: str | ||
:param word_list: optional word list file for ignoring certain words. | ||
:rtype: (ahocorasick.Automaton, str) | ||
:returns: an automaton, and an iterated sha1 hash of the words in the word list. | ||
""" | ||
# Dynamic import due to optional-dependency | ||
try: | ||
import ahocorasick | ||
except ImportError: # pragma: no cover | ||
print('Please install the `pyahocorasick` package to use --word-list') | ||
raise | ||
|
||
# See https://pyahocorasick.readthedocs.io/en/latest/ | ||
# for more information. | ||
automaton = ahocorasick.Automaton() | ||
word_list_hash = hashlib.sha1() | ||
|
||
with open(word_list) as f: | ||
for line in f.readlines(): | ||
# .lower() to make everything case-insensitive | ||
line = line.lower().strip() | ||
if len(line) > 3: | ||
word_list_hash.update(line.encode('utf-8')) | ||
automaton.add_word(line, line) | ||
|
||
automaton.make_automaton() | ||
|
||
return ( | ||
automaton, | ||
word_list_hash.hexdigest(), | ||
) | ||
|
||
|
||
def get_root_directory(): # pragma: no cover | ||
return os.path.realpath( | ||
os.path.join( | ||
os.path.dirname(__file__), | ||
'../../', | ||
), | ||
) | ||
|
||
|
||
def get_git_sha(path): | ||
"""Returns the sha of the git checkout at the input path. | ||
:type path: str | ||
:param path: directory of the git checkout | ||
:rtype: str|None | ||
:returns: git sha of the input path | ||
""" | ||
try: | ||
with open(os.devnull, 'w') as fnull: | ||
return subprocess.check_output( | ||
['git', 'rev-parse', '--verify', 'HEAD'], | ||
stderr=fnull, | ||
cwd=path, | ||
).decode('utf-8').split()[0] | ||
except (subprocess.CalledProcessError, OSError, IndexError): # pragma: no cover | ||
return None | ||
|
||
|
||
def get_git_remotes(path): | ||
"""Returns a list of unique git remotes of the checkout | ||
at the input path. | ||
:type path: str | ||
:param path: directory of the git checkout | ||
:rtype: List<str>|None | ||
:returns: A list of unique git urls | ||
""" | ||
try: | ||
with open(os.devnull, 'w') as fnull: | ||
git_remotes = subprocess.check_output( | ||
['git', 'remote', '-v'], | ||
stderr=fnull, | ||
cwd=path, | ||
).decode('utf-8').split('\n') | ||
return list({ | ||
git_remote.split()[1] | ||
for git_remote | ||
in git_remotes | ||
if len(git_remote) > 2 # split('\n') produces an empty list | ||
}) | ||
except (subprocess.CalledProcessError, OSError): # pragma: no cover | ||
return None | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.