persist

package
v2.39.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: Apache-2.0 Imports: 3 Imported by: 341

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPolicyArray added in v2.37.0

func LoadPolicyArray(rule []string, m model.Model)

LoadPolicyArray loads a policy rule to model.

func LoadPolicyLine

func LoadPolicyLine(line string, m model.Model)

LoadPolicyLine loads a text line as a policy rule to model.

Types

type Adapter

type Adapter interface {
	// LoadPolicy loads all policy rules from the storage.
	LoadPolicy(model model.Model) error
	// SavePolicy saves all policy rules to the storage.
	SavePolicy(model model.Model) error

	// AddPolicy adds a policy rule to the storage.
	// This is part of the Auto-Save feature.
	AddPolicy(sec string, ptype string, rule []string) error
	// RemovePolicy removes a policy rule from the storage.
	// This is part of the Auto-Save feature.
	RemovePolicy(sec string, ptype string, rule []string) error
	// RemoveFilteredPolicy removes policy rules that match the filter from the storage.
	// This is part of the Auto-Save feature.
	RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error
}

Adapter is the interface for Casbin adapters.

type BatchAdapter added in v2.2.2

type BatchAdapter interface {
	Adapter
	// AddPolicies adds policy rules to the storage.
	// This is part of the Auto-Save feature.
	AddPolicies(sec string, ptype string, rules [][]string) error
	// RemovePolicies removes policy rules from the storage.
	// This is part of the Auto-Save feature.
	RemovePolicies(sec string, ptype string, rules [][]string) error
}

BatchAdapter is the interface for Casbin adapters with multiple add and remove policy functions.

type Dispatcher added in v2.18.0

type Dispatcher interface {
	// AddPolicies adds policies rule to all instance.
	AddPolicies(sec string, ptype string, rules [][]string) error
	// RemovePolicies removes policies rule from all instance.
	RemovePolicies(sec string, ptype string, rules [][]string) error
	// RemoveFilteredPolicy removes policy rules that match the filter from all instance.
	RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error
	// ClearPolicy clears all current policy in all instances
	ClearPolicy() error
	// UpdatePolicy updates policy rule from all instance.
	UpdatePolicy(sec string, ptype string, oldRule, newRule []string) error
	// UpdatePolicies updates some policy rules from all instance
	UpdatePolicies(sec string, ptype string, oldrules, newRules [][]string) error
	// UpdateFilteredPolicies deletes old rules and adds new rules.
	UpdateFilteredPolicies(sec string, ptype string, oldRules [][]string, newRules [][]string) error
}

Dispatcher is the interface for Casbin dispatcher

type FilteredAdapter

type FilteredAdapter interface {
	Adapter

	// LoadFilteredPolicy loads only policy rules that match the filter.
	LoadFilteredPolicy(model model.Model, filter interface{}) error
	// IsFiltered returns true if the loaded policy has been filtered.
	IsFiltered() bool
}

FilteredAdapter is the interface for Casbin adapters supporting filtered policies.

type UpdatableAdapter added in v2.14.0

type UpdatableAdapter interface {
	Adapter
	// UpdatePolicy updates a policy rule from storage.
	// This is part of the Auto-Save feature.
	UpdatePolicy(sec string, ptype string, oldRule, newPolicy []string) error
	// UpdatePolicies updates some policy rules to storage, like db, redis.
	UpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) error
	// UpdateFilteredPolicies deletes old rules and adds new rules.
	UpdateFilteredPolicies(sec string, ptype string, newPolicies [][]string, fieldIndex int, fieldValues ...string) ([][]string, error)
}

UpdatableAdapter is the interface for Casbin adapters with add update policy function.

type Watcher

type Watcher interface {
	// SetUpdateCallback sets the callback function that the watcher will call
	// when the policy in DB has been changed by other instances.
	// A classic callback is Enforcer.LoadPolicy().
	SetUpdateCallback(func(string)) error
	// Update calls the update callback of other instances to synchronize their policy.
	// It is usually called after changing the policy in DB, like Enforcer.SavePolicy(),
	// Enforcer.AddPolicy(), Enforcer.RemovePolicy(), etc.
	Update() error
	// Close stops and releases the watcher, the callback function will not be called any more.
	Close()
}

Watcher is the interface for Casbin watchers.

type WatcherEx added in v2.4.0

type WatcherEx interface {
	Watcher
	// UpdateForAddPolicy calls the update callback of other instances to synchronize their policy.
	// It is called after Enforcer.AddPolicy()
	UpdateForAddPolicy(sec, ptype string, params ...string) error
	// UpdateForRemovePolicy calls the update callback of other instances to synchronize their policy.
	// It is called after Enforcer.RemovePolicy()
	UpdateForRemovePolicy(sec, ptype string, params ...string) error
	// UpdateForRemoveFilteredPolicy calls the update callback of other instances to synchronize their policy.
	// It is called after Enforcer.RemoveFilteredNamedGroupingPolicy()
	UpdateForRemoveFilteredPolicy(sec, ptype string, fieldIndex int, fieldValues ...string) error
	// UpdateForSavePolicy calls the update callback of other instances to synchronize their policy.
	// It is called after Enforcer.RemoveFilteredNamedGroupingPolicy()
	UpdateForSavePolicy(model model.Model) error
	// UpdateForAddPolicies calls the update callback of other instances to synchronize their policy.
	// It is called after Enforcer.AddPolicies()
	UpdateForAddPolicies(sec string, ptype string, rules ...[]string) error
	// UpdateForRemovePolicies calls the update callback of other instances to synchronize their policy.
	// It is called after Enforcer.RemovePolicies()
	UpdateForRemovePolicies(sec string, ptype string, rules ...[]string) error
}

WatcherEx is the strengthen for Casbin watchers.

type WatcherUpdatable added in v2.14.0

type WatcherUpdatable interface {
	Watcher
	// UpdateForUpdatePolicy calls the update callback of other instances to synchronize their policy.
	// It is called after Enforcer.UpdatePolicy()
	UpdateForUpdatePolicy(oldRule, newRule []string) error
	// UpdateForUpdatePolicies calls the update callback of other instances to synchronize their policy.
	// It is called after Enforcer.UpdatePolicies()
	UpdateForUpdatePolicies(oldRules, newRules [][]string) error
}

WatcherUpdatable is the strengthen for Casbin watchers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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