Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
babenek committed Dec 13, 2024
1 parent 9ede9b7 commit 6e95195
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 5 additions & 11 deletions credsweeper/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from typing import Any, List, Optional, Union, Dict, Sequence, Tuple

import pandas as pd
from colorama import Fore
from colorama.ansi import Style
from colorama import Style

# Directory of credsweeper sources MUST be placed before imports to avoid circular import error
APP_PATH = Path(__file__).resolve().parent
Expand Down Expand Up @@ -436,15 +435,10 @@ def export_results(self) -> None:
is_exported = True
for credential in credentials:
for line_data in credential.line_data_list:
print(Style.BRIGHT + credential.rule_name \
+ f" {line_data.info or line_data.path}:{line_data.line_num}"
+ Style.RESET_ALL)
if self.hashed:
print(Fore.LIGHTGREEN_EX \
+ line_data.get_hash_or_subtext(line_data.line, self.hashed) \
+ Style.RESET_ALL)
else:
print(f"{line_data.get_colored_line(self.subtext)}")
# bright rule name and path or info
print(Style.BRIGHT + credential.rule_name +
f" {line_data.info or line_data.path}:{line_data.line_num}" + Style.RESET_ALL)
print(line_data.get_colored_line(hashed=self.hashed, subtext=self.subtext))

if is_exported is False:
for credential in credentials:
Expand Down
8 changes: 7 additions & 1 deletion credsweeper/credentials/line_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,13 @@ def to_json(self, hashed: bool, subtext: bool) -> Dict:
reported_output = {k: v for k, v in full_output.items() if k in self.config.line_data_output}
return reported_output

def get_colored_line(self, subtext: bool = False) -> str:
def get_colored_line(self, hashed: bool, subtext: bool = False) -> str:
"""Represents the LineData with a value, separator, and variable color formatting"""
if hashed:
# return colored hash
return Fore.LIGHTGREEN_EX \
+ self.get_hash_or_subtext(self.line, hashed, self.value_start if subtext else None) \
+ Style.RESET_ALL
# at least, value must present
line = self.line[:self.value_start] \
+ Fore.LIGHTYELLOW_EX \
Expand Down

0 comments on commit 6e95195

Please sign in to comment.