config

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultAlgorithm = "fast"

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 (
	ErrChallengeDifficultyTooLow  = errors.New("config.ChallengeRules: difficulty is too low (must be >= 1)")
	ErrChallengeDifficultyTooHigh = errors.New("config.ChallengeRules: difficulty is too high (must be <= 64)")
	ErrChallengeMustHaveAlgorithm = errors.New("config.ChallengeRules: must have algorithm name set")
)
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")
)
View Source
var (
	ErrInvalidOpenGraphConfig   = errors.New("config.OpenGraph: invalid OpenGraph configuration")
	ErrOpenGraphTTLDoesNotParse = errors.New("config.OpenGraph: ttl does not parse as a Duration, see https://pkg.go.dev/time#ParseDuration (formatted like 5m -> 5 minutes, 2h -> 2 hours, etc)")
	ErrOpenGraphMissingProperty = errors.New("config.OpenGraph: default opengraph tags missing a property")
)
View Source
var (
	ErrNoStoreBackend      = errors.New("config.Store: no backend defined")
	ErrUnknownStoreBackend = errors.New("config.Store: unknown backend")
)
View Source
var (
	ErrNoThresholdRulesDefined             = errors.New("config: no thresholds defined")
	ErrThresholdMustHaveName               = errors.New("config.Threshold: must set name")
	ErrThresholdMustHaveExpression         = errors.New("config.Threshold: must set expression")
	ErrThresholdChallengeMustHaveChallenge = errors.New("config.Threshold: a threshold with the CHALLENGE action must have challenge set")
	ErrThresholdCannotHaveWeighAction      = errors.New("config.Threshold: a threshold cannot have the WEIGH action")

	DefaultThresholds = []Threshold{
		{
			Name: "legacy-anubis-behaviour",
			Expression: &ExpressionOrList{
				Expression: "weight > 0",
			},
			Action: RuleChallenge,
			Challenge: &ChallengeRules{
				Algorithm:  "fast",
				Difficulty: anubis.DefaultDifficulty,
				ReportAs:   anubis.DefaultDifficulty,
			},
		},
	}
)
View Source
var ErrMissingValue = errors.New("config: missing value")
View Source
var (
	ErrNotCountryCode = errors.New("config.Bot: invalid country code")
)
View Source
var (
	ErrPrivateASN = errors.New("bot.ASNs: you have specified a private use ASN")
)

Functions

This section is empty.

Types

type ASNs added in v1.20.0

type ASNs struct {
	Match []uint32 `json:"match"`
}

func (*ASNs) Valid added in v1.20.0

func (a *ASNs) Valid() error

type BotConfig

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

	// Thoth features
	GeoIP *GeoIP `json:"geoip,omitempty"`
	ASNs  *ASNs  `json:"asns,omitempty"`
}

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  string `json:"algorithm,omitempty" yaml:"algorithm,omitempty"`
	Difficulty int    `json:"difficulty,omitempty" yaml:"difficulty,omitempty"`
	ReportAs   int    `json:"report_as,omitempty" yaml:"report_as,omitempty"`
}

func (ChallengeRules) Valid

func (cr ChallengeRules) Valid() error

type Config

type Config struct {
	Bots        []BotConfig
	Thresholds  []Threshold
	DNSBL       bool
	Impressum   *Impressum
	OpenGraph   OpenGraph
	StatusCodes StatusCodes
	Store       *Store
}

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:"-" yaml:"-"`
	All        []string `json:"all,omitempty" yaml:"all,omitempty"`
	Any        []string `json:"any,omitempty" yaml:"any,omitempty"`
}

func (ExpressionOrList) Equal added in v1.18.0

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

func (*ExpressionOrList) MarshalJSON added in v1.20.0

func (eol *ExpressionOrList) MarshalJSON() ([]byte, error)

func (*ExpressionOrList) MarshalYAML added in v1.20.0

func (eol *ExpressionOrList) MarshalYAML() (any, error)

func (ExpressionOrList) String added in v1.20.0

func (eol ExpressionOrList) String() string

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 GeoIP added in v1.20.0

type GeoIP struct {
	Countries []string `json:"countries"`
}

func (*GeoIP) Valid added in v1.20.0

func (g *GeoIP) 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 Impressum added in v1.20.0

type Impressum struct {
	Footer string        `json:"footer" yaml:"footer"`
	Page   ImpressumPage `json:"page" yaml:"page"`
}

func (Impressum) Render added in v1.20.0

func (i Impressum) Render(_ context.Context, w io.Writer) error

func (Impressum) Valid added in v1.20.0

func (i Impressum) Valid() error

type ImpressumPage added in v1.20.0

type ImpressumPage struct {
	Title string `json:"title" yaml:"title"`
	Body  string `json:"body" yaml:"body"`
}

func (ImpressumPage) Render added in v1.20.0

func (ip ImpressumPage) Render(_ context.Context, w io.Writer) error

func (ImpressumPage) Valid added in v1.20.0

func (ip ImpressumPage) Valid() error

type OpenGraph added in v1.20.0

type OpenGraph struct {
	Enabled      bool              `json:"enabled" yaml:"enabled"`
	ConsiderHost bool              `json:"considerHost" yaml:"enabled"`
	Override     map[string]string `json:"override,omitempty" yaml:"override,omitempty"`
	TimeToLive   time.Duration     `json:"ttl" yaml:"ttl"`
}

type Rule

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

func (Rule) Valid added in v1.20.0

func (r Rule) Valid() error

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

type Store added in v1.21.0

type Store struct {
	Backend    string          `json:"backend"`
	Parameters json.RawMessage `json:"parameters"`
}

func (*Store) Valid added in v1.21.0

func (s *Store) Valid() error

type Threshold added in v1.20.0

type Threshold struct {
	Name       string            `json:"name" yaml:"name"`
	Expression *ExpressionOrList `json:"expression" yaml:"expression"`
	Action     Rule              `json:"action" yaml:"action"`
	Challenge  *ChallengeRules   `json:"challenge" yaml:"challenge"`
}

func (Threshold) Valid added in v1.20.0

func (t Threshold) Valid() error

type Weight added in v1.20.0

type Weight struct {
	Adjust int `json:"adjust" yaml:"adjust"`
}

Jump to

Keyboard shortcuts

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