common

package
v3.85.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetricsNamespace is the namespace for all metrics.
	MetricsNamespace = "trufflehog"
	// MetricsSubsystem is the subsystem for all metrics.
	MetricsSubsystem = "scanner"
)
View Source
const AlphaNumPattern = "0-9a-zA-Z"
View Source
const DefaultResponseTimeout = 5 * time.Second
View Source
const EmailPattern = `` /* 458-byte string literal not displayed */
View Source
const HexPattern = "0-9a-f"
View Source
const RegexPattern = "0-9a-z"
View Source
const SubDomainPattern = `\b([A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?)\b`
View Source
const UUIDPattern = `\b([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\b`
View Source
const UUIDPatternUpperCase = `\b([0-9A-Z]{8}-[0-9A-Z]{4}-[0-9A-Z]{4}-[0-9A-Z]{4}-[0-9A-Z]{12})\b`

Variables

View Source
var (
	KB, MB, GB, TB, PB = 1e3, 1e6, 1e9, 1e12, 1e15
)

Functions

func AddStringSliceItem

func AddStringSliceItem(item string, slice *[]string)

func BuildRegex added in v3.6.9

func BuildRegex(pattern string, specialChar string, length int) string

Custom Regex functions

func BuildRegexJWT added in v3.6.9

func BuildRegexJWT(firstRange, secondRange, thirdRange string) string

func CancellableRead added in v3.78.1

func CancellableRead[T any](ctx context.Context, ch <-chan T) (T, error)

CancellableRead blocks on receiving an item from the channel but can be cancelled by the context. If the channel is closed, a ChannelClosedErr is returned. If both the context is cancelled and the channel read would succeed, either operation will be performed randomly, however priority is given to context cancellation.

func CancellableWrite added in v3.44.0

func CancellableWrite[T any](ctx context.Context, ch chan<- T, item T) error

CancellableWrite blocks on writing the item to the channel but can be cancelled by the context. If both the context is cancelled and the channel write would succeed, either operation will be performed randomly, however priority is given to context cancellation.

func ConstantResponseHttpClient added in v3.46.0

func ConstantResponseHttpClient(statusCode int, body string) *http.Client

func ExportErrors added in v3.67.6

func ExportErrors(errs ...error) []error

ExportErrors converts a list of errors into []ExportError.

func IsBinary added in v3.63.5

func IsBinary(filename string) bool

IsBinary returns true if the file extension is in the binaryExtensions list.

func IsDone

func IsDone(ctx context.Context) bool

func PinnedCertPool

func PinnedCertPool() *x509.CertPool

func PinnedRetryableHttpClient

func PinnedRetryableHttpClient() *http.Client

func RandomID added in v3.46.0

func RandomID(length int) string

RandomID returns a random string of the given length.

func RangeValidation added in v3.6.9

func RangeValidation(rangeInput string) bool

func Recover added in v3.10.0

func Recover(ctx context.Context)

Recover handles panics and reports to Sentry.

func RecoverWithExit added in v3.12.1

func RecoverWithExit(ctx context.Context)

RecoverWithExit handles panics and reports to Sentry before exiting.

func RemoveStringSliceItem

func RemoveStringSliceItem(item string, slice *[]string)

func ResponseContainsSubstring added in v3.42.0

func ResponseContainsSubstring(reader io.ReadCloser, target string) (bool, error)

func RetryableHTTPClient added in v3.68.4

func RetryableHTTPClient(opts ...ClientOption) *http.Client

func RetryableHTTPClientTimeout added in v3.68.4

func RetryableHTTPClientTimeout(timeOutSeconds int64, opts ...ClientOption) *http.Client

func SaneHttpClient

func SaneHttpClient() *http.Client

func SaneHttpClientTimeOut

func SaneHttpClientTimeOut(timeout time.Duration) *http.Client

SaneHttpClientTimeOut adds a custom timeout for some scanners

func SkipFile

func SkipFile(filename string) bool

SkipFile returns true if the file extension is in the ignoredExtensions list.

func SliceContainsString added in v3.82.8

func SliceContainsString(origTargetString string, stringSlice []string, ignoreCase bool) (bool, string, int)

SliceContainsString searches a slice to determine if it contains a specified string. Returns the index of the first match in the slice.

func ToUpperCase added in v3.6.9

func ToUpperCase(input string) string

Types

type ChannelClosedErr added in v3.78.1

type ChannelClosedErr struct{}

ChannelClosedErr indicates that a read was performed from a closed channel.

func (ChannelClosedErr) Error added in v3.78.1

func (ChannelClosedErr) Error() string

type ClientOption added in v3.68.4

type ClientOption func(*retryablehttp.Client)

ClientOption configures how we set up the client.

func WithBackoff added in v3.68.4

func WithBackoff(b retryablehttp.Backoff) ClientOption

WithBackoff allows setting a custom backoff policy.

func WithCheckRetry added in v3.68.4

func WithCheckRetry(cr retryablehttp.CheckRetry) ClientOption

WithCheckRetry allows setting a custom CheckRetry policy.

func WithMaxRetries added in v3.68.4

func WithMaxRetries(retries int) ClientOption

WithMaxRetries allows setting a custom maximum number of retries.

func WithRetryWaitMax added in v3.68.4

func WithRetryWaitMax(wait time.Duration) ClientOption

WithRetryWaitMax allows setting a custom maximum retry wait.

func WithRetryWaitMin added in v3.68.4

func WithRetryWaitMin(wait time.Duration) ClientOption

WithRetryWaitMin allows setting a custom minimum retry wait.

func WithTimeout added in v3.68.4

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout allows setting a custom timeout.

type CustomTransport

type CustomTransport struct {
	T http.RoundTripper
}

func NewCustomTransport

func NewCustomTransport(T http.RoundTripper) *CustomTransport

func (*CustomTransport) RoundTrip

func (t *CustomTransport) RoundTrip(req *http.Request) (*http.Response, error)

type ExportError added in v3.67.6

type ExportError string

ExportError is an implementation of error that can be JSON marshalled. It must be a public exported type for this reason.

func (ExportError) Error added in v3.67.6

func (e ExportError) Error() string

type FakeTransport added in v3.45.0

type FakeTransport struct {
	CreateResponse func(req *http.Request) (*http.Response, error)
}

func (FakeTransport) RoundTrip added in v3.45.0

func (t FakeTransport) RoundTrip(req *http.Request) (*http.Response, error)

type Filter

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

func FilterEmpty

func FilterEmpty() *Filter

FilterEmpty returns a Filter that always passes.

func FilterFromFiles

func FilterFromFiles(includeFilterPath, excludeFilterPath string) (*Filter, error)

FilterFromFiles creates a Filter using the rules in the provided include and exclude files.

func (*Filter) Pass

func (filter *Filter) Pass(object string) bool

Pass returns true if the include FilterRuleSet matches the pattern and the exclude FilterRuleSet does not match.

type FilterRuleSet

type FilterRuleSet []regexp.Regexp

func FilterRulesFromFile

func FilterRulesFromFile(source string) (*FilterRuleSet, error)

FilterRulesFromFile loads the list of regular expression filter rules in `source` and creates a FilterRuleSet.

func (*FilterRuleSet) Matches

func (rules *FilterRuleSet) Matches(object string) bool

Matches will return true if any of the regular expressions in the FilterRuleSet match the pattern.

type RegexState added in v3.42.0

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

func PasswordRegexCheck added in v3.42.0

func PasswordRegexCheck(pattern string) RegexState

PasswordRegexCheck constructs an username usernameRegex pattern from a given pattern of excluded characters.

func UsernameRegexCheck added in v3.42.0

func UsernameRegexCheck(pattern string) RegexState

UsernameRegexCheck constructs an username usernameRegex pattern from a given pattern of excluded characters.

func (RegexState) Matches added in v3.42.0

func (r RegexState) Matches(data []byte) []string

type Secret

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

func GetSecret

func GetSecret(ctx context.Context, gcpProject, name string) (secret *Secret, err error)

func GetSecretFromEnv added in v3.0.2

func GetSecretFromEnv(filename string) (secret *Secret, err error)

func GetTestSecret

func GetTestSecret(ctx context.Context) (secret *Secret, err error)

func (*Secret) MustGetField

func (s *Secret) MustGetField(name string) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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