helpers

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DetectionVerifier

type DetectionVerifier func(string, 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).

    [^\S\r\n]*                 the regex without new line uses it, the \S is negative of all whitespaces and by using ^ on this we get all the whitespaces, together with \r\n we have all whitespaces except new lines.

	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 NewDefaultKeyValueRegexWithoutNewLine added in v1.0.9

func NewDefaultKeyValueRegexWithoutNewLine(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 RegexDetectorBuilder added in v1.0.9

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

func NewRegexDetectorBuilder added in v1.0.9

func NewRegexDetectorBuilder(secretType string, regex ...string) *RegexDetectorBuilder

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

func (*RegexDetectorBuilder) Build added in v1.0.9

func (builder *RegexDetectorBuilder) Build() secrets.Detector

func (*RegexDetectorBuilder) WithKeyValueRegexWithoutNewLine added in v1.0.9

func (builder *RegexDetectorBuilder) WithKeyValueRegexWithoutNewLine() *RegexDetectorBuilder

WithKeyValueRegexWithoutNewLine set the default regex that tries to find key-value matches, to not accept new lines between the key and the value it can be used in cases that the secret ends with delimiter (for example base64 ends with =) in that case the match be corrupted with the default regex.

func (*RegexDetectorBuilder) WithVerifier added in v1.0.9

func (builder *RegexDetectorBuilder) WithVerifier(verifier DetectionVerifier) *RegexDetectorBuilder

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