Skip to content

Commit

Permalink
clear cache for plugins scan diff (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
achiar99 authored Nov 21, 2024
1 parent 0868d32 commit caf2564
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion detect_secrets/core/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Generator
from typing import Iterable
from typing import List
from typing import Optional
from typing import Set
from typing import Tuple
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -196,7 +197,7 @@ def scan_diff(diff: str) -> Generator[PotentialSecret, None, None]:
return

for filename, lines in _get_lines_from_diff(diff):
yield from _process_line_based_plugins(lines, filename=filename)
yield from _process_line_based_plugins(lines, filename=filename, is_scan_diff=True)


def scan_for_allowlisted_secrets_in_file(filename: str) -> Generator[PotentialSecret, None, None]:
Expand Down Expand Up @@ -338,6 +339,7 @@ def _get_lines_from_diff(diff: str) -> \
def _process_line_based_plugins(
lines: List[Tuple[int, str, bool, bool]],
filename: str,
is_scan_diff: Optional[bool] = False,
) -> Generator[PotentialSecret, None, None]:
line_content = [line[1] for line in lines]

Expand Down Expand Up @@ -384,6 +386,7 @@ def _process_line_based_plugins(
line_number=line_number,
context=code_snippet,
raw_context=raw_code_snippet,
is_scan_diff=is_scan_diff,
):
secret.is_removed = is_removed
secret.is_added = is_added
Expand Down
10 changes: 8 additions & 2 deletions detect_secrets/plugins/private_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def analyze_line(
line_number: int = 0,
context: Optional[CodeSnippet] = None,
raw_context: Optional[CodeSnippet] = None,
is_scan_diff: Optional[bool] = False,
**kwargs: Any,
) -> Set[PotentialSecret]:
output: Set[PotentialSecret] = set()
Expand All @@ -86,9 +87,14 @@ def analyze_line(
),
)

if not output and filename not in self._analyzed_files \
to_analyze_line = filename not in self._analyzed_files
if is_scan_diff:
to_analyze_line = True

if not output and to_analyze_line \
and 0 < self.get_file_size(filename) < PrivateKeyDetector.MAX_FILE_SIZE:
self._analyzed_files.add(filename)
if not is_scan_diff:
self._analyzed_files.add(filename)
file_content = self.read_file(filename)
if file_content:
output.update(
Expand Down

0 comments on commit caf2564

Please sign in to comment.