helpers

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRegexDetector

func NewRegexDetector(secretType string, regex ...string) secrets.Detector

NewRegexDetector creates a generic regex detector. It can be used as an embedded struct to implement most types of regex based detectors.

func NewRegexDetectorWithVerifier

func NewRegexDetectorWithVerifier(verifier DetectionVerifier, secretType string, regex ...string) secrets.Detector

NewRegexDetectorWithVerifier creates a generic regex detector. It can be used as an embedded struct to implement most types of regex based detectors. verifier function should check if the string matched by regex is a valid detection.

Types

type DetectionVerifier

type DetectionVerifier func(string) bool

type KeyValueRegex

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

KeyValueRegex should match strings in a structure of key (default or injected via NewKeyValueRegex), a delimiter,

and value injected via argument.

Expected pattern examples:

key: value
"key": "value"
key=value
"key" = 'value'
key := value
[ "key" ] = [ "value" ] ;
value
"value"

Regex breakdown:

Key:
  (?i)(?:(?:var|let|set|dim|declare|export|const|readonly)[\t ]+)?(?-i)
                           an optional declaration keyword from commonly used languages like bash, powershell, JS.
                           supported keywords: var, let, set, dim, declare, export, const, readonly

  \[?[\t ]*['"]?			an optional prefix: a square bracket ([) and a single (') or double quote (").
  ([\t a-zA-Z0-9\/_-]+)	default key name pattern, comprised of letters, digits, spaces, tabs, slash (/),
                           underscore (_) and dash (-).
  							captured as capture group #1.
  ['"]?[\t ]*\]?			an optional suffix: single (') or double quote (") and a square bracket (]).

Delimiter:
  \s*						optional whitespaces between key and delimiter.
  (:|=|:=)					a delimiter: colon (:), equal sign (=), or colon equal sign (:=).
  							captured as capture group #2.
  \s*						optional whitespaces between delimiter and value.

  (?: )?					key and delimiter regex are surrounded by an optional non-capturing group.
  							That makes the key and delimiter optional (they are capture only if both exist).

Value:
  \[?[\t ]*['"]?			an optional prefix: a square bracket ([) and a single (') or double quote (").
  (%s)               		the value regex will be injected here.
  							captured as capture group #3.
  							internal capturing groups inside value regex will be captured as #4-#n.
  ['"]?[\t ]*\]?[\t ]*;?	an optional suffix: single (') or double quote ("), a square bracket (]) and a semicolon (;).

func NewDefaultKeyValueRegex

func NewDefaultKeyValueRegex(valueRegex ...string) *KeyValueRegex

func NewKeyValueRegex

func NewKeyValueRegex(keyRegex, valueRegex string) *KeyValueRegex

func (*KeyValueRegex) FindAll

func (r *KeyValueRegex) FindAll(in string) ([]MatchResult, error)

type MatchResult

type MatchResult struct {
	FullMatch       string
	Key             string
	Delimiter       string
	Value           string
	ValueSubmatches []string
}

type ValueRegex

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

func NewKeyRegex

func NewKeyRegex(regex ...string) *ValueRegex

func NewValueRegex

func NewValueRegex(regex ...string) *ValueRegex

func (*ValueRegex) Find

func (arr *ValueRegex) Find(in string) string

func (*ValueRegex) FindAll

func (arr *ValueRegex) FindAll(in string) []string

func (*ValueRegex) Match

func (arr *ValueRegex) Match(in string) bool

Jump to

Keyboard shortcuts

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