config

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoBotRulesDefined                 = errors.New("config: must define at least one (1) bot rule")
	ErrBotMustHaveName                   = errors.New("config.Bot: must set name")
	ErrBotMustHaveUserAgentOrPath        = errors.New("config.Bot: must set either user_agent_regex, path_regex, headers_regex, or remote_addresses")
	ErrBotMustHaveUserAgentOrPathNotBoth = errors.New("config.Bot: must set either user_agent_regex, path_regex, and not both")
	ErrUnknownAction                     = errors.New("config.Bot: unknown action")
	ErrInvalidUserAgentRegex             = errors.New("config.Bot: invalid user agent regex")
	ErrInvalidPathRegex                  = errors.New("config.Bot: invalid path regex")
	ErrInvalidHeadersRegex               = errors.New("config.Bot: invalid headers regex")
	ErrInvalidCIDR                       = errors.New("config.Bot: invalid CIDR")
	ErrRegexEndsWithNewline              = errors.New("config.Bot: regular expression ends with newline (try >- instead of > in yaml)")
	ErrInvalidImportStatement            = errors.New("config.ImportStatement: invalid source file")
	ErrCantSetBotAndImportValuesAtOnce   = errors.New("config.BotOrImport: can't set bot rules and import values at the same time")
	ErrMustSetBotOrImportRules           = errors.New("config.BotOrImport: rule definition is invalid, you must set either bot rules or an import statement, not both")
	ErrStatusCodeNotValid                = errors.New("config.StatusCode: status code not valid, must be between 100 and 599")
)
View Source
var (
	ErrChallengeRuleHasWrongAlgorithm = errors.New("config.Bot.ChallengeRules: algorithm is invalid")
	ErrChallengeDifficultyTooLow      = errors.New("config.Bot.ChallengeRules: difficulty is too low (must be >= 1)")
	ErrChallengeDifficultyTooHigh     = errors.New("config.Bot.ChallengeRules: difficulty is too high (must be <= 64)")
)
View Source
var (
	ErrExpressionOrListMustBeStringOrObject = errors.New("config: this must be a string or an object")
	ErrExpressionEmpty                      = errors.New("config: this expression is empty")
	ErrExpressionCantHaveBoth               = errors.New("config: expression block can't contain multiple expression types")
)

Functions

This section is empty.

Types

type Algorithm

type Algorithm string
const (
	AlgorithmUnknown Algorithm = ""
	AlgorithmFast    Algorithm = "fast"
	AlgorithmSlow    Algorithm = "slow"
)

type BotConfig

type BotConfig struct {
	UserAgentRegex *string           `json:"user_agent_regex"`
	PathRegex      *string           `json:"path_regex"`
	HeadersRegex   map[string]string `json:"headers_regex"`
	Expression     *ExpressionOrList `json:"expression"`
	Challenge      *ChallengeRules   `json:"challenge,omitempty"`
	Name           string            `json:"name"`
	Action         Rule              `json:"action"`
	RemoteAddr     []string          `json:"remote_addresses"`
}

func (BotConfig) Valid

func (b BotConfig) Valid() error

func (BotConfig) Zero added in v1.17.0

func (b BotConfig) Zero() bool

type BotOrImport added in v1.17.0

type BotOrImport struct {
	*BotConfig       `json:",inline"`
	*ImportStatement `json:",inline"`
}

func (*BotOrImport) Valid added in v1.17.0

func (boi *BotOrImport) Valid() error

type ChallengeRules

type ChallengeRules struct {
	Algorithm  Algorithm `json:"algorithm"`
	Difficulty int       `json:"difficulty"`
	ReportAs   int       `json:"report_as"`
}

func (ChallengeRules) Valid

func (cr ChallengeRules) Valid() error

type Config

type Config struct {
	Bots        []BotConfig
	DNSBL       bool
	StatusCodes StatusCodes
}

func Load added in v1.17.0

func Load(fin io.Reader, fname string) (*Config, error)

func (Config) Valid

func (c Config) Valid() error

type ExpressionOrList added in v1.18.0

type ExpressionOrList struct {
	Expression string   `json:"-"`
	All        []string `json:"all"`
	Any        []string `json:"any"`
}

func (ExpressionOrList) Equal added in v1.18.0

func (eol ExpressionOrList) Equal(rhs *ExpressionOrList) bool

func (*ExpressionOrList) UnmarshalJSON added in v1.18.0

func (eol *ExpressionOrList) UnmarshalJSON(data []byte) error

func (*ExpressionOrList) Valid added in v1.18.0

func (eol *ExpressionOrList) Valid() error

type ImportStatement added in v1.17.0

type ImportStatement struct {
	Import string `json:"import"`
	Bots   []BotConfig
}

func (*ImportStatement) Valid added in v1.17.0

func (is *ImportStatement) Valid() error

type Rule

type Rule string
const (
	RuleUnknown   Rule = ""
	RuleAllow     Rule = "ALLOW"
	RuleDeny      Rule = "DENY"
	RuleChallenge Rule = "CHALLENGE"
	RuleBenchmark Rule = "DEBUG_BENCHMARK"
)

type StatusCodes added in v1.17.1

type StatusCodes struct {
	Challenge int `json:"CHALLENGE"`
	Deny      int `json:"DENY"`
}

func (StatusCodes) Valid added in v1.17.1

func (sc StatusCodes) Valid() error

Jump to

Keyboard shortcuts

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