-
Module trufflehog3.core
Core trufflehog3 logic.
Functions
-
def scan(
open_in_new
    target: str,
    config: Config,
    rules: Iterable[Union[Entropy, Pattern]],
    processes: int,
) ‑> Iterable[Issue] -
Return issues found during target path scan.
-
def diff(old: Iterable[Issue], new: Iterable[Issue], only_new: bool = False) ‑> Iterable[Issue]
open_in_new -
Return diff from the given lists of issues.
By default, full diff will be returned, i.e. issues that are not found in either of the given lists. In case
only_new
is True, only issues that are present in thenew
list, but not in theold
one will be returned. -
def load_config(path: str, **kwargs) ‑> Config
open_in_new -
Load config from file or search for it in the specified directory.
Note
Uses
DEFAULT_CONFIG_FILE
filename for searching config file in directory.All
kwargs
are passed toConfig.update
method after loading.Examples
Basic usage examples. Load config from file
>>> path = Path() / DEFAULT_CONFIG_FILE >>> config = load_config(path) >>> config.ignore_nosecret False
Provide values to override config
>>> config = load_config(path, ignore_nosecret=True) >>> config.ignore_nosecret True
Search config in directory
>>> config = load_config(Path()) >>> config.ignore_nosecret False
-
def load_rules(path: str, severity: Severity = LOW) ‑> Iterable[Union[Entropy, Pattern]]
open_in_new -
Load rules from file.
Examples
Basic usage examples
>>> len(load_rules(DEFAULT_RULES_FILE)) 31 >>> len(load_rules(DEFAULT_RULES_FILE, Severity.MEDIUM)) 28 >>> len(load_rules(DEFAULT_RULES_FILE, Severity.HIGH)) 2
-
def load(cls: type, file: str = None) ‑> Union[Model, List[Model]]
open_in_new -
Load any model from YAML file.
Note
File defaults to
sys.stdin
. Seecore.loads
for more details.Examples
Define a class with the necessary properties
>>> @attr.s ... class Test(Model): ... version: str = attr.ib() ... numbers: List[int] = attr.ib()
Load model
>>> obj = load(Test, "tests/data/test_load.yml") >>> obj.asdict() {'version': 'v1', 'numbers': [1, 2]}
Load list of models
>>> objs = load(Test, "tests/data/test_load_list.yml") >>> [obj.asdict() for obj in objs] [{'version': 'v1', 'numbers': [1, 2]}, {'version': 'v2', 'numbers': [3]}]
-
def loads(cls: type, raw: str) ‑> Union[Model, List[Model]]
open_in_new -
Load any model from YAML string.
Note
Model is instantiated using provided
cls
. If YAML contains a list, each item is instantiated usingcls
Examples
Define a class with the necessary properties
>>> @attr.s ... class Test(Model): ... version: str = attr.ib() ... numbers: List[int] = attr.ib()
Load model
>>> raw = ''' ... version: v1 ... numbers: ... - 1 ... - 2 ... ''' >>> obj = loads(Test, raw) >>> obj.asdict() {'version': 'v1', 'numbers': [1, 2]}
Load list of models
>>> raw = ''' ... - version: v1 ... numbers: ... - 1 ... - 2 ... - version: v2 ... numbers: ... - 3 ... ''' >>> objs = loads(Test, raw) >>> [obj.asdict() for obj in objs] [{'version': 'v1', 'numbers': [1, 2]}, {'version': 'v2', 'numbers': [3]}]
-
def render(issues: Iterable[Issue], format: Format, file: str = None)
open_in_new -
Render issues to file in given format.
-
def renders(issues: Iterable[Issue], format: Format) ‑> str
open_in_new -
Render issues to string in given format.
-
def dump(obj: Union[Model, List[Model]], file: str = None)
open_in_new -
Dump model to file.
Notes
File defaults to
sys.stdout
. Seecore.dumps
for more details. -
def dumps(model: Union[Model, List[Model]], **kwargs) ‑> str
open_in_new -
Dump model to string.
Note
Model is serialized to YAML using its own
asdict
method. If model is a list, each item is serialized using its ownasdict
method.All
kwargs
are directly passed toyaml.safe_dump
.Examples
Define a class with the necessary properties
>>> @attr.s ... class Test(Model): ... version: str = attr.ib() ... numbers: List[int] = attr.ib()
Dump model
>>> obj = Test(version="v1", numbers=[1, 2]) >>> print(dumps(obj, sort_keys=False), end="") version: v1 numbers: - 1 - 2
Dump list of models
>>> objs = [ ... Test(version="v1", numbers=[1, 2]), ... Test(version="v2", numbers=[3]), ... ] >>> print(dumps(objs, sort_keys=False), end="") - version: v1 numbers: - 1 - 2 - version: v2 numbers: - 3
-
def write(raw: str, file: str = None)
open_in_new -
Write string to file.
Note
File defaults to
sys.stdout
.