Help us shape the future of Go! Take the 2026 Go Developer Survey

rules

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareRevision added in v1.0.0

func CompareRevision(a, b string) int

CompareRevision compares two revision strings using a natural-order comparator. Returns -1 if a < b, 0 if a == b, and 1 if a > b.

func LoadSeedFiles added in v1.0.0

func LoadSeedFiles(root string) ([]rules.SeedFile, error)

LoadSeedFiles recursively scans the root directory for any rules.yaml files.

func LoadSeedFilesFromFS added in v1.0.0

func LoadSeedFilesFromFS(fsys fs.FS, root string) ([]rules.SeedFile, error)

LoadSeedFilesFromFS recursively scans the given fs.FS starting at root for any rules.yaml files.

func TokenizeRevision added in v1.0.0

func TokenizeRevision(s string) []revisionToken

TokenizeRevision splits a revision string into its constituent numeric or letter tokens, treating any non-alphanumeric character as a boundary separator.

func ValidateSeedFile added in v1.0.0

func ValidateSeedFile(f rules.SeedFile) error

ValidateSeedFile validates the content of a SeedFile against structural requirements.

Types

type CompiledPath added in v1.0.0

type CompiledPath struct {
	SegmentCount int
	StaticPrefix string
	PathRegex    string
}

func CompileMatch added in v1.0.0

func CompileMatch(match string) (CompiledPath, error)

CompileMatch compiles a match path pattern into a CompiledPath structure.

type ResourceMapper

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

ResourceMapper implements the full pipeline: lookup → match → resolve.

func NewResourceMapper

func NewResourceMapper(repo repository.RuleRepository, matcher RuleMatcherInterface, resolver TupleResolverInterface) *ResourceMapper

NewResourceMapper creates a new ResourceMapper.

func (*ResourceMapper) Map

func (rm *ResourceMapper) Map(ctx context.Context, userID, method, path string) ([]client.ClientBatchCheckItem, *rules.RuleWithTuples, error)

Map takes an HTTP method and path, looks up candidate rules from the database, matches the first applicable rule, resolves its tuple, and returns the result.

type ResourceMapperInterface

type ResourceMapperInterface interface {
	Map(ctx context.Context, userID, method, path string) ([]client.ClientBatchCheckItem, *rules.RuleWithTuples, error)
}

type RuleMatcher

type RuleMatcher struct{}

RuleMatcher matches an incoming path against a set of candidate rules.

func NewRuleMatcher

func NewRuleMatcher() *RuleMatcher

NewRuleMatcher creates a new RuleMatcher.

func (*RuleMatcher) Match

func (m *RuleMatcher) Match(candidates []*rules.RuleWithTuples, path string) (*rules.RuleWithTuples, error)

Match iterates over candidates (already sorted by priority ASC from the query) and returns the first rule whose path_regex matches the given path.

type RuleMatcherInterface

type RuleMatcherInterface interface {
	Match(candidates []*rules.RuleWithTuples, path string) (*rules.RuleWithTuples, error)
}

type RuleSeeder added in v1.0.0

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

func NewRuleSeeder added in v1.0.0

func (*RuleSeeder) SeedService added in v1.0.0

func (s *RuleSeeder) SeedService(ctx context.Context, file rules.SeedFile) (inserted bool, skipped bool, err error)

SeedService runs the seeding process for a single service SeedFile.

type TupleResolver

type TupleResolver struct{}

TupleResolver resolves a RuleWithTuples + regex match into an OpenFGA Tuple.

func NewTupleResolver

func NewTupleResolver() *TupleResolver

NewTupleResolver creates a new TupleResolver.

func (*TupleResolver) Resolve

func (r *TupleResolver) Resolve(userID string, rule *rules.RuleWithTuples, matches rules.RegexMatches) ([]*rules.Tuple, error)

Resolve builds an openfga Tuple from the rule tuple specifications, substituting dynamic object_resource_id values (wrapped in braces like "{groupId}") with the corresponding capture group value from the regex match.

type TupleResolverInterface

type TupleResolverInterface interface {
	Resolve(userID string, rule *rules.RuleWithTuples, matches rules.RegexMatches) ([]*rules.Tuple, error)
}

Jump to

Keyboard shortcuts

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