pynydus.security.gitleaks¶
Gitleaks CLI connector for secret detection.
Wraps the external gitleaks binary to scan directories for secrets (API keys,
tokens, passwords) and build SecretRecord entries with {{SECRET_NNN}}
placeholders. Descriptions never contain secret substrings.
Requires gitleaks v8+ on PATH or NYDUS_GITLEAKS_PATH.
Module Contents¶
Classes¶
One row from gitleaks JSON report output. |
Functions¶
Resolve the |
|
Run |
|
Replace gitleaks matches with placeholders and build secret records. |
Data¶
API¶
- pynydus.security.gitleaks.logger¶
‘getLogger(…)’
- class pynydus.security.gitleaks.Finding¶
One row from gitleaks JSON report output.
Attributes: file: Absolute path to the file (as reported by gitleaks). rule_id: Rule identifier. match: Matched substring in the file. start_line: 1-based line number. start_column: Start column (1-based, gitleaks convention). end_column: End column. secret: Optional
Secretfield from JSON. preferred replacement text when it appears verbatim in the file content.
- pynydus.security.gitleaks.find_gitleaks() str | None¶
Resolve the
gitleaksexecutable path.Returns: Absolute path to the binary, or
Noneif not found.Note:
NYDUS_GITLEAKS_PATHis checked first, thenPATHviashutil.which.
- pynydus.security.gitleaks.run_gitleaks_scan(root: pathlib.Path) list[pynydus.security.gitleaks.Finding]¶
Run
gitleaks directoryon root and parse JSON findings.Args: root: Directory tree to scan (v8.18+
gitleaks directorymode).Returns: Parsed
Findingrows. Empty if the report file is empty.Raises: RuntimeError: If the binary is missing or gitleaks exits with a code other than 0 (success) or 1 (leaks found).
Note: Exit code
1means leaks were found, not a failed run. Report JSON is written to a temp file because-r -is unreliable on some platforms.
- pynydus.security.gitleaks.apply_gitleaks_findings(files: dict[str, str], findings: list[pynydus.security.gitleaks.Finding], *, temp_root: pathlib.Path, start_index: int = 1) tuple[dict[str, str], list[pynydus.api.schemas.SecretRecord], int]¶
Replace gitleaks matches with placeholders and build secret records.
Args: files: Original path-to-content map (keys match the tree under temp_root). findings: Parsed gitleaks rows for that tree. temp_root: Temp directory path that was passed to :func:
run_gitleaks_scan(used to map absolute paths back to keys). start_index: Starting index for{{SECRET_NNN}}numbering.Returns: Tuple of
(redacted file map, new SecretRecord list, next index)after the last placeholder.