rules

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action represents the action to take when a rule matches

const (
	ActionAllow Action = "allow" // Allow access without authentication
	ActionAuth  Action = "auth"  // Require authentication
	ActionDeny  Action = "deny"  // Deny access (403)
)

type AllMatcher

type AllMatcher struct{}

AllMatcher matches all paths

func NewAllMatcher

func NewAllMatcher() *AllMatcher

func (*AllMatcher) Match

func (m *AllMatcher) Match(path string) bool

type Config

type Config struct {
	Rules []RuleConfig `yaml:"rules,omitempty"`
}

Config represents the rules configuration

func GetDefaultConfig

func GetDefaultConfig() *Config

GetDefaultConfig returns the default rules configuration (require auth for all)

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the rules configuration

type Evaluator

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

Evaluator evaluates path access rules

func NewEvaluator

func NewEvaluator(config *Config) (*Evaluator, error)

NewEvaluator creates a new rule evaluator from configuration

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(path string) Action

Evaluate evaluates a path against all rules and returns the action Rules are evaluated in order, and the first matching rule determines the action

func (*Evaluator) ShouldAllow

func (e *Evaluator) ShouldAllow(path string) bool

ShouldAllow returns true if the path should be allowed without authentication

func (*Evaluator) ShouldAuth

func (e *Evaluator) ShouldAuth(path string) bool

ShouldAuth returns true if the path requires authentication

func (*Evaluator) ShouldDeny

func (e *Evaluator) ShouldDeny(path string) bool

ShouldDeny returns true if the path should be denied (403)

type ExactMatcher

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

ExactMatcher matches exact paths

func NewExactMatcher

func NewExactMatcher(path string) *ExactMatcher

func (*ExactMatcher) Match

func (m *ExactMatcher) Match(path string) bool

type Matcher

type Matcher interface {
	// Match returns true if the path matches
	Match(path string) bool
}

Matcher is an interface for path matching

type MinimatchMatcher

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

MinimatchMatcher matches paths using glob/minimatch patterns

func NewMinimatchMatcher

func NewMinimatchMatcher(pattern string) (*MinimatchMatcher, error)

func (*MinimatchMatcher) Match

func (m *MinimatchMatcher) Match(path string) bool

type PrefixMatcher

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

PrefixMatcher matches path prefixes

func NewPrefixMatcher

func NewPrefixMatcher(prefix string) *PrefixMatcher

func (*PrefixMatcher) Match

func (m *PrefixMatcher) Match(path string) bool

type RegexMatcher

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

RegexMatcher matches paths using regular expressions

func NewRegexMatcher

func NewRegexMatcher(pattern string) (*RegexMatcher, error)

func (*RegexMatcher) Match

func (m *RegexMatcher) Match(path string) bool

type Rule

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

Rule represents a compiled rule with a matcher and action

type RuleConfig

type RuleConfig struct {
	// Matchers (only one should be specified)
	Exact     string `yaml:"exact,omitempty"`     // Exact path match
	Prefix    string `yaml:"prefix,omitempty"`    // Prefix match
	Regex     string `yaml:"regex,omitempty"`     // Regular expression match
	Minimatch string `yaml:"minimatch,omitempty"` // Glob/minimatch pattern
	All       *bool  `yaml:"all,omitempty"`       // Match all paths (must be true if specified)

	// Action to take when matched
	Action Action `yaml:"action"`

	// Optional description for documentation
	Description string `yaml:"description,omitempty"`
}

RuleConfig represents a single rule in the configuration

func (*RuleConfig) Validate

func (r *RuleConfig) Validate() error

Validate validates a single rule configuration

Jump to

Keyboard shortcuts

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