Documentation
¶
Index ¶
- func LoadPolicyArray(rule []string, m model.Model) error
- func LoadPolicyLine(line string, m model.Model) error
- type Adapter
- type BatchAdapter
- type ContextAdapter
- type ContextBatchAdapter
- type ContextFilteredAdapter
- type ContextUpdatableAdapter
- type Dispatcher
- type FilteredAdapter
- type UpdatableAdapter
- type UpdatableWatcher
- type Watcher
- type WatcherEx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadPolicyArray ¶ added in v2.37.0
LoadPolicyArray loads 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 ContextAdapter ¶ added in v2.77.0
type ContextAdapter interface { // LoadPolicyCtx loads all policy rules from the storage with context. LoadPolicyCtx(ctx context.Context, model model.Model) error // SavePolicyCtx saves all policy rules to the storage with context. SavePolicyCtx(ctx context.Context, model model.Model) error // AddPolicyCtx adds a policy rule to the storage with context. // This is part of the Auto-Save feature. AddPolicyCtx(ctx context.Context, sec string, ptype string, rule []string) error // RemovePolicyCtx removes a policy rule from the storage with context. // This is part of the Auto-Save feature. RemovePolicyCtx(ctx context.Context, sec string, ptype string, rule []string) error // RemoveFilteredPolicyCtx removes policy rules that match the filter from the storage with context. // This is part of the Auto-Save feature. RemoveFilteredPolicyCtx(ctx context.Context, sec string, ptype string, fieldIndex int, fieldValues ...string) error }
ContextAdapter provides a context-aware interface for Casbin adapters.
type ContextBatchAdapter ¶ added in v2.90.0
type ContextBatchAdapter interface { ContextAdapter // AddPoliciesCtx adds policy rules to the storage. // This is part of the Auto-Save feature. AddPoliciesCtx(ctx context.Context, sec string, ptype string, rules [][]string) error // RemovePoliciesCtx removes policy rules from the storage. // This is part of the Auto-Save feature. RemovePoliciesCtx(ctx context.Context, sec string, ptype string, rules [][]string) error }
ContextBatchAdapter is the context-aware interface for Casbin adapters with multiple add and remove policy functions.
type ContextFilteredAdapter ¶ added in v2.90.0
type ContextFilteredAdapter interface { ContextAdapter // LoadFilteredPolicyCtx loads only policy rules that match the filter. LoadFilteredPolicyCtx(ctx context.Context, model model.Model, filter interface{}) error // IsFilteredCtx returns true if the loaded policy has been filtered. IsFilteredCtx(ctx context.Context) bool }
ContextFilteredAdapter is the context-aware interface for Casbin adapters supporting filtered policies.
type ContextUpdatableAdapter ¶ added in v2.90.0
type ContextUpdatableAdapter interface { ContextAdapter // UpdatePolicyCtx updates a policy rule from storage. // This is part of the Auto-Save feature. UpdatePolicyCtx(ctx context.Context, sec string, ptype string, oldRule, newRule []string) error // UpdatePoliciesCtx updates some policy rules to storage, like db, redis. UpdatePoliciesCtx(ctx context.Context, sec string, ptype string, oldRules, newRules [][]string) error // UpdateFilteredPoliciesCtx deletes old rules and adds new rules. UpdateFilteredPoliciesCtx(ctx context.Context, sec string, ptype string, newRules [][]string, fieldIndex int, fieldValues ...string) ([][]string, error) }
ContextUpdatableAdapter is the context-aware interface for Casbin adapters with add update policy function.
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, newRule []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, newRules [][]string, fieldIndex int, fieldValues ...string) ([][]string, error) }
UpdatableAdapter is the interface for Casbin adapters with add update policy function.
type UpdatableWatcher ¶ added in v2.54.0
type UpdatableWatcher interface { Watcher // UpdateForUpdatePolicy calls the update callback of other instances to synchronize their policy. // It is called after Enforcer.UpdatePolicy() UpdateForUpdatePolicy(sec string, ptype string, oldRule, newRule []string) error // UpdateForUpdatePolicies calls the update callback of other instances to synchronize their policy. // It is called after Enforcer.UpdatePolicies() UpdateForUpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) error }
UpdatableWatcher is strengthened for Casbin watchers.
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 strengthened Casbin watchers.