Skip to content

Commit 09824b0

Browse files
committed
surpressing output
1 parent 81447f5 commit 09824b0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

truffleHog/truffleHog.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def main():
4747
for regex in rules:
4848
regexes[regex] = rules[regex]
4949
do_entropy = str2bool(args.do_entropy)
50-
output = find_strings(args.git_url, args.since_commit, args.max_depth, args.output_json, args.do_regex, do_entropy)
50+
output = find_strings(args.git_url, args.since_commit, args.max_depth, args.output_json, args.do_regex, do_entropy, surpress_output=False)
5151
project_path = output["project_path"]
5252
shutil.rmtree(project_path, onerror=del_rw)
5353

@@ -206,7 +206,7 @@ def regex_check(printableDiff, commit_time, branch_name, prev_commit, blob, comm
206206
regex_matches.append(foundRegex)
207207
return regex_matches
208208

209-
def diff_worker(diff, curr_commit, prev_commit, branch_name, commitHash, custom_regexes, do_entropy, do_regex, printJson):
209+
def diff_worker(diff, curr_commit, prev_commit, branch_name, commitHash, custom_regexes, do_entropy, do_regex, printJson, surpress_output):
210210
issues = []
211211
for blob in diff:
212212
printableDiff = blob.diff.decode('utf-8', errors='replace')
@@ -221,8 +221,9 @@ def diff_worker(diff, curr_commit, prev_commit, branch_name, commitHash, custom_
221221
if do_regex:
222222
found_regexes = regex_check(printableDiff, commit_time, branch_name, prev_commit, blob, commitHash, custom_regexes)
223223
foundIssues += found_regexes
224-
for foundIssue in foundIssues:
225-
print_results(printJson, foundIssue)
224+
if not surpress_output:
225+
for foundIssue in foundIssues:
226+
print_results(printJson, foundIssue)
226227
issues += foundIssues
227228
return issues
228229

@@ -234,7 +235,7 @@ def handle_results(output, output_dir, foundIssues):
234235
output["foundIssues"].append(result_path)
235236
return output
236237

237-
def find_strings(git_url, since_commit=None, max_depth=1000000, printJson=False, do_regex=False, do_entropy=True, custom_regexes={}):
238+
def find_strings(git_url, since_commit=None, max_depth=1000000, printJson=False, do_regex=False, do_entropy=True, surpress_output=True, custom_regexes={}):
238239
output = {"foundIssues": []}
239240
project_path = clone_git_repo(git_url)
240241
repo = Repo(project_path)
@@ -265,12 +266,12 @@ def find_strings(git_url, since_commit=None, max_depth=1000000, printJson=False,
265266
continue
266267
else:
267268
diff = prev_commit.diff(curr_commit, create_patch=True)
268-
foundIssues = diff_worker(diff, curr_commit, prev_commit, branch_name, commitHash, custom_regexes, do_entropy, do_regex, printJson)
269+
foundIssues = diff_worker(diff, curr_commit, prev_commit, branch_name, commitHash, custom_regexes, do_entropy, do_regex, printJson, surpress_output)
269270
output = handle_results(output, output_dir, foundIssues)
270271
prev_commit = curr_commit
271272
# Handling the first commit
272273
diff = curr_commit.diff(NULL_TREE, create_patch=True)
273-
foundIssues = diff_worker(diff, curr_commit, prev_commit, branch_name, commitHash, custom_regexes, do_entropy, do_regex, printJson)
274+
foundIssues = diff_worker(diff, curr_commit, prev_commit, branch_name, commitHash, custom_regexes, do_entropy, do_regex, printJson, surpress_output)
274275
output = handle_results(output, output_dir, foundIssues)
275276
output["project_path"] = project_path
276277
output["clone_uri"] = git_url

0 commit comments

Comments
 (0)