scan

package
v0.164.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package scan centralizes secret-scanning helpers used by gk guard.

gk guard scans with the gitleaks ruleset embedded in gk and spawns the gitleaks binary only for repos with a gitleaks config. This file provides the adapter primitives for that path: JSON parsing of gitleaks output, version probing, binary detection, and invocation.

Index

Constants

This section is empty.

Variables

View Source
var ErrGitleaksNotInstalled = errors.New("gitleaks binary not found in $PATH")

ErrGitleaksNotInstalled is returned by callers that require gitleaks but could not find it in $PATH. Not used by the parser itself — intended for SCAN-10 / GD-07 wiring.

Functions

func FindGitleaks

func FindGitleaks() (path, version string, ok bool)

FindGitleaks locates the gitleaks binary via $PATH and, if present, runs `gitleaks version` to extract a version string. Returns (path, version, ok=true) when detected. When missing or the version probe fails, version may be empty but path/ok are still set accurately.

func HasGitleaksConfig added in v0.154.0

func HasGitleaksConfig(dir string) bool

HasGitleaksConfig reports whether gitleaks would load a config or ignore file from dir (or from GITLEAKS_CONFIG*). The ruleset embedded in gk does not read them, so a scan that must honor them has to run gitleaks.

Types

type GitleaksFinding

type GitleaksFinding struct {
	Description string  `json:"Description"`
	File        string  `json:"File"`
	StartLine   int     `json:"StartLine"`
	EndLine     int     `json:"EndLine"`
	StartColumn int     `json:"StartColumn"`
	EndColumn   int     `json:"EndColumn"`
	Match       string  `json:"Match"`
	Secret      string  `json:"Secret"`
	RuleID      string  `json:"RuleID"`
	Commit      string  `json:"Commit"`
	Author      string  `json:"Author"`
	Email       string  `json:"Email"`
	Date        string  `json:"Date"`
	Message     string  `json:"Message"`
	Entropy     float64 `json:"Entropy"`
}

GitleaksFinding mirrors the shape of a single entry in gitleaks' JSON report output (gitleaks v8+, `--report-format json`). Only the fields gk needs are included; gitleaks emits more keys (Tags, Fingerprint, Entropy, etc.) that downstream rules can pick up later via a json.RawMessage on GitleaksFinding if needed.

func ParseGitleaksFindings

func ParseGitleaksFindings(data []byte) ([]GitleaksFinding, error)

ParseGitleaksFindings parses a gitleaks JSON report payload into typed findings. Empty input (or a payload containing just `null` / `[]`) returns an empty slice without error — gitleaks emits those shapes when no findings are present.

func RunGitleaks

func RunGitleaks(ctx context.Context, opts GitleaksOptions) ([]GitleaksFinding, error)

RunGitleaks spawns the gitleaks binary, has it write a JSON report to a temp file, and parses the findings via ParseGitleaksFindings. The report goes to a file because gitleaks 8.30.1 on macOS rejected --report-path /dev/stdout with "permission denied".

type GitleaksOptions

type GitleaksOptions struct {
	// WorkDir runs gitleaks with the given directory as cwd. Empty uses the
	// process cwd.
	WorkDir string
	// Mode selects the gitleaks scan subcommand ("git", "dir", "detect", ...).
	// Empty defaults to "git" (scan the git history).
	Mode string
	// ExtraArgs appends additional flags after the defaults (e.g. "--log-opts=-1").
	ExtraArgs []string
	// Redact masks discovered secret values in the output. Defaults to true
	// because gk prints findings to terminals / CI logs by default.
	Redact bool
}

GitleaksOptions customize RunGitleaks invocation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL