profiles

package
v1.120.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadResult

type LoadResult struct {
	Loaded    []ProfileMetadata // Successfully loaded profiles
	Failed    []string          // Profile names that failed to load
	Errors    []error           // Errors encountered during loading
	RuleCount int               // Total rules across all profiles
}

LoadResult contains the outcome of loading profiles.

type MatchResult

type MatchResult struct {
	Matched bool              // Whether any rule matched
	Rules   []botguard.Rule   // Rules that matched
	Signals []botguard.Signal // Signals generated from matches
	Exempt  bool              // Whether request is exempted from further scoring
}

MatchResult contains the outcome of matching a request against rules.

type Profile

type Profile struct {
	// Name is the profile identifier (e.g., "wordpress", "generic").
	Name string `yaml:"profile"`

	// Version is the profile schema version.
	Version string `yaml:"version"`

	// Description explains what this profile protects.
	Description string `yaml:"description"`

	// Inherits lists parent profiles whose rules are included.
	// Rules from inherited profiles run before this profile's rules.
	Inherits []string `yaml:"inherits"`

	// AlwaysActive means this profile runs for all requests.
	// If false, profile must be explicitly enabled in config.
	AlwaysActive bool `yaml:"always_active"`

	// Rules are the detection patterns for this profile.
	Rules []botguard.Rule `yaml:"rules"`

	// SafePaths are paths that should never be scored by this profile.
	// Useful for exempting known-good endpoints.
	SafePaths []string `yaml:"safe_paths"`
}

Profile defines a set of detection rules for a specific application or use case. Profiles are loaded from YAML files in /etc/nftban/conf.d/botguard/profiles/.

type ProfileFile

type ProfileFile struct {
	Profile Profile `yaml:"profile"`
}

ProfileFile is the top-level structure of a profile YAML file.

type ProfileLoader

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

ProfileLoader manages loading and caching of profile YAML files.

func NewProfileLoader

func NewProfileLoader(dir string) *ProfileLoader

NewProfileLoader creates a new loader for the given profiles directory.

func (*ProfileLoader) ClearCache

func (pl *ProfileLoader) ClearCache()

ClearCache clears the profile cache, forcing reload on next access.

func (*ProfileLoader) ListAvailable

func (pl *ProfileLoader) ListAvailable() ([]string, error)

ListAvailable returns the names of available profile files.

func (*ProfileLoader) LoadActiveProfiles

func (pl *ProfileLoader) LoadActiveProfiles(names []string, features botguard.FeatureFlags) (*RuleRegistry, LoadResult)

LoadActiveProfiles loads the specified profiles and returns a rule registry. If features are disabled, returns an empty registry.

type ProfileMetadata

type ProfileMetadata struct {
	Name         string   // Profile name
	Version      string   // Profile version
	Path         string   // File path where loaded from
	RuleCount    int      // Number of rules in profile
	Inherits     []string // Parent profiles
	AlwaysActive bool     // Whether profile is always active
}

ProfileMetadata contains information about a loaded profile.

type RuleRegistry

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

RuleRegistry holds compiled rules for efficient matching.

func NewRuleRegistry

func NewRuleRegistry() *RuleRegistry

NewRuleRegistry creates an empty rule registry.

func (*RuleRegistry) AddRules

func (r *RuleRegistry) AddRules(rules []botguard.Rule)

AddRules adds rules to the registry, compiling patterns as needed.

func (*RuleRegistry) AddSafePaths

func (r *RuleRegistry) AddSafePaths(patterns []string)

AddSafePaths adds safe path patterns to the registry.

func (*RuleRegistry) AllRules

func (r *RuleRegistry) AllRules() []botguard.Rule

AllRules returns a copy of all rules in the registry.

func (*RuleRegistry) GetCompiledPattern

func (r *RuleRegistry) GetCompiledPattern(ruleID string) *regexp.Regexp

GetCompiledPattern returns the compiled regex for a rule ID.

func (*RuleRegistry) GetRule

func (r *RuleRegistry) GetRule(id string) *botguard.Rule

GetRule returns a rule by ID, or nil if not found.

func (*RuleRegistry) GetRulesByGroup

func (r *RuleRegistry) GetRulesByGroup(group botguard.RuleGroup) []botguard.Rule

GetRulesByGroup returns all rules for a given group.

func (*RuleRegistry) Groups

func (r *RuleRegistry) Groups() []botguard.RuleGroup

Groups returns all groups that have rules registered.

func (*RuleRegistry) IsSafePath

func (r *RuleRegistry) IsSafePath(path string) bool

IsSafePath returns true if the path matches any safe path pattern.

func (*RuleRegistry) RuleCount

func (r *RuleRegistry) RuleCount() int

RuleCount returns the total number of rules in the registry.

Jump to

Keyboard shortcuts

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