detect

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AbstractRegexpEngine describes the name of the used regular expression engine.
	AbstractRegexpEngine = "std"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AbstractRegexp

type AbstractRegexp interface {
	// MatchString reports whether the string s contains any match of the regular expression.
	MatchString(s string) bool

	// FindAllStringIndex returns a slice of all successive matches of the expression. A return value of nil
	// indicates no match.
	FindAllStringIndex(s string, n int) [][]int

	// FindStringSubmatch returns a slice of strings holding the text of the leftmost match of the regular
	// expression in s and the matches, if any, of its subexpressions. A return value of nil indicates no
	// match.
	FindStringSubmatch(s string) []string
}

AbstractRegexp is an abstract interface for a regular expression.

func CloneRegexp

func CloneRegexp(re *regexp.Regexp) AbstractRegexp

CloneRegexp clones the given regular expression re.

func CompileRegexp

func CompileRegexp(expr string) (AbstractRegexp, error)

CompileRegexp parses the given expression and returns, if successful, an AbstractRegexp.

func MustCompileRegexp

func MustCompileRegexp(expr string) AbstractRegexp

MustCompileRegexp is like CompileRegexp but panics if the expression cannot be parsed. It simplifies safe initialization of global variables holding compiled abstract regular expressions.

type Detector

type Detector struct {
	// contains filtered or unexported fields
}

Detector wraps a set of rules to detect secrets.

func NewDetector

func NewDetector(ruleFns []GitleaksRuleFunction, customs []string, enclosed bool) (*Detector, error)

NewDetector creates a new Detector object with rules from the given set of Gitleaks rule functions and additional custom rules.

func (*Detector) Detect

func (d *Detector) Detect(r io.Reader) ([]*Finding, error)

Detect will detect all secrets in the given reader stream.

type Finding

type Finding struct {
	RuleID      string    // ID of the rule responsible for the finding.
	Description string    // Description of the secret found.
	Secret      string    // The actual secret.
	Match       string    // The match containing the secret.
	Location    *Location // The location of the match.
}

Finding wraps all relevant information for a finding.

type GitleaksRuleFunction

type GitleaksRuleFunction func() *config.Rule

GitleaksRuleFunction is a function that generates a rule.

type Location

type Location struct {
	StartIdx     int // Start index of the match
	EndIdx       int // End index of the match
	StartLine    int // Text line the start index falls in
	EndLine      int // Text line the end index falls in
	StartColumn  int // Column in the start line corresponding to the start index
	EndColumn    int // Column in the end line corresponding to the end index
	StartLineIdx int // Index of the beginning of the start line
	EndLineIdx   int // Index of the first character after the end line
}

Location represents a location in a string.

func (*Location) Line

func (l *Location) Line(s string) string

Line returns the line(s) of the location within s.

type Locator

type Locator struct {
	// contains filtered or unexported fields
}

Locator allows to locate indexes in a string.

func NewLocator

func NewLocator(s string) *Locator

NewLocator creates a Locator object for the given string.

func (*Locator) Find

func (l *Locator) Find(startIdx int, endIdx int) *Location

Find returns the location for a given index pair.

type Rule

type Rule struct {
	RuleID      string             // Unique identifier for this rule
	Description string             // Description of the rule
	Entropy     float64            // Minimum Shannon entropy a regex group must have to be considered a secret
	SecretGroup int                // Used to extract secret from regex match
	Regex       AbstractRegexp     // Used to detect secrets
	Allowlists  []config.Allowlist // Allows a rule to be ignored for specific regexes, paths, and/or commits
}

Rule contains information that define details on how to detect secrets.

func NewRuleFromGitleaksRule

func NewRuleFromGitleaksRule(r *config.Rule) *Rule

NewRuleFromGitleaksRule creates a cleaned-up Rule object from a Gitlab's rule.

func NewRuleFromRegExp added in v1.2.0

func NewRuleFromRegExp(re *regexp.Regexp, idx int) *Rule

NewRuleFromRegExp creates a Rule object from a regular expression.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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