-
Module trufflehog3.search
Supported search algorithms.
Functions
-
def search(
open_in_new
    file: File,
    rules: Iterable[Union[Entropy, Pattern]],
    exclude: Iterable[Exclude] = None,
    ignore_nosecret: bool = False,
    context: int = 0,
) ‑> Iterable[Issue] -
Return issues found using provided rules.
Examples
Entropy-based search
>>> rule = Entropy() >>> file = File( ... path="/path/to/code.py", ... content="password = 'abcdefghijklmnopqrstuvwxyz'", ... ) >>> for issue in search(file, [rule]): ... print(issue.secret) abcdefghijklmnopqrstuvwxyz
Pattern-based search
>>> rule = Pattern( ... id="bad-password-letmein", ... message="Bad Password 'letmein'", ... pattern="letmein", ... severity="high", ... ) >>> file = File( ... path="/path/to/code.py", ... content="password = 'letmein'", ... ) >>> for issue in search(file, [rule]): ... print(issue.secret) letmein
With exclude
>>> exc = Exclude(message="Not a secret", paths=["*.py"]) >>> len(search(file, [rule], exclude=[exc])) 0
With inline exclude
>>> file = File( ... path="/path/to/code.py", ... content="password = 'letmein' # nosecret", ... ) >>> len(search(file, [rule])) 0
>>> file = File( ... path="/path/to/code.py", ... content="password = 'letmein' # nosecret: bad-password-letmein", ... ) >>> len(search(file, [rule])) 0
-
def searchiter(
open_in_new
    file: File,
    rules: Iterable[Union[Entropy, Pattern]],
    exclude: Iterable[Exclude] = None,
    ignore_nosecret: bool = False,
    context: int = 0,
) ‑> Iterator[Issue] -
Yield issues found using provided rules.