loader

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package loader provides rules loading via parser-kit (multi-source fallback/merge).

Index

Constants

View Source
const (
	ModeOnlyLocal                  = "ONLY_LOCAL"
	ModeOnlyRemote                 = "ONLY_REMOTE"
	ModeRemoteFirst                = "REMOTE_FIRST"
	ModeRemoteFirstAllowRemoteFail = "REMOTE_FIRST_ALLOW_REMOTE_FAILED"
	ModeLocalFirst                 = "LOCAL_FIRST"
	ModeLocalFirstAllowRemoteFail  = "LOCAL_FIRST_ALLOW_REMOTE_FAILED"
)

Merge/environment modes. These mirror the historical MODE values so behavior is preserved; the values are matched case-insensitively after trimming.

Variables

This section is empty.

Functions

func BuildLoadOptions

func BuildLoadOptions(cfg *cmd.Config, appMode string) *parserkit.LoadOptions

BuildLoadOptions builds parser-kit LoadOptions from warden config and app mode.

func BuildSources

func BuildSources(rulesFile, dataDir, configURL, auth, appMode string) []parserkit.Source

BuildSources builds parser-kit sources for the given mode (priority order). When dataDir is non-empty, all *.json files in that directory are added as file sources (sorted by name).

Types

type LoadResult added in v0.14.0

type LoadResult struct {
	// Users is the resolved rule set. It is only meaningful when Err is nil.
	Users []define.AllowListUser
	// Source records where the resolved rule set came from.
	Source Source
	// Version is a short content hash of the resolved rule set (empty when Err != nil).
	Version string
	// LoadedAt is when the result was produced.
	LoadedAt time.Time
	// Degraded is true when the mode allowed a remote failure and the result was
	// served from local/last-known-good instead of the preferred remote source.
	Degraded bool
	// DegradedReason is a short, non-sensitive reason code (e.g. "remote_failed").
	DegradedReason string
	// Err is the combined root cause when loading failed. It never carries secrets.
	Err error
}

LoadResult is the outcome of a load attempt. It separates "what was read" from "how the mode decided to use it" so callers (and the background refresher) can reason about degraded operation without inspecting the concrete error.

type RulesLoader

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

RulesLoader wraps parser-kit DataLoader and exposes FromFile/Load by (rulesFile, configURL, auth).

func NewRulesLoader

func NewRulesLoader(cfg *cmd.Config, appMode string) (*RulesLoader, error)

NewRulesLoader creates a RulesLoader using cfg and appMode.

func (*RulesLoader) FromFile

func (r *RulesLoader) FromFile(ctx context.Context, path string) ([]define.AllowListUser, error)

FromFile loads rules from a local file.

func (*RulesLoader) Load

func (r *RulesLoader) Load(ctx context.Context, rulesFile, dataDir, configURL, auth string) ([]define.AllowListUser, error)

Load loads rules from sources built from (rulesFile, dataDir, configURL, auth) and r.appMode. It preserves the historical signature and error semantics by delegating to LoadWithResult.

func (*RulesLoader) LoadWithResult added in v0.14.0

func (r *RulesLoader) LoadWithResult(ctx context.Context, rulesFile, dataDir, configURL, auth string) LoadResult

LoadWithResult loads rules and returns a structured LoadResult that separates the read source from the mode decision. Remote failures no longer short-circuit before the mode policy is applied: modes that tolerate remote failure fall back to the local rule set and mark the result Degraded, while strict modes surface the root cause. This function never returns partial/unvalidated data with a nil Err.

type Source added in v0.14.0

type Source string

Source identifies where a successfully loaded rule set originated.

const (
	// SourceRemote indicates the rules came from the remote configuration endpoint.
	SourceRemote Source = "remote"
	// SourceLocal indicates the rules came from local file(s)/directory.
	SourceLocal Source = "local"
	// SourceMerged indicates the rules came from a merge of remote and local.
	SourceMerged Source = "merged"
	// SourceNone indicates no rules were loaded.
	SourceNone Source = "none"
)

Jump to

Keyboard shortcuts

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