menu
  • Module trufflehog3.core

    Core trufflehog3 logic.

Functions
            
                

                def scan(
    target: str,
    config: Config,
    rules: Iterable[Union[EntropyPattern]],
    processes: int,
) ‑> Iterable[Issue]
open_in_new

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 the new list, but not in the old 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 to Config.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[EntropyPattern]]
            
            
    
    
        
            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. See core.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 using cls

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. See core.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 own asdict method.

All kwargs are directly passed to yaml.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.