8000 feat: add missing params in WatcherUpdatable interface by Rainshaw · Pull Request #1100 · casbin/casbin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add missing params in WatcherUpdatable interface #1100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ func (e *Enforcer) updatePolicy(sec string, ptype string, oldRule []string, newR

if e.shouldNotify() {
var err error
if watcher, ok := e.watcher.(persist.WatcherUpdatable); ok {
err = watcher.UpdateForUpdatePolicy(oldRule, newRule)
if watcher, ok := e.watcher.(persist.UpdatableWatcher); ok {
err = watcher.UpdateForUpdatePolicy(sec, ptype, oldRule, newRule)
} else {
err = e.watcher.Update()
}
Expand All @@ -388,8 +388,8 @@ func (e *Enforcer) updatePolicies(sec string, ptype string, oldRules [][]string,

if e.shouldNotify() {
var err error
if watcher, ok := e.watcher.(persist.WatcherUpdatable); ok {
err = watcher.UpdateForUpdatePolicies(oldRules, newRules)
if watcher, ok := e.watcher.(persist.UpdatableWatcher); ok {
err = watcher.UpdateForUpdatePolicies(sec, ptype, oldRules, newRules)
} else {
err = e.watcher.Update()
}
Expand Down Expand Up @@ -448,8 +448,8 @@ func (e *Enforcer) updateFilteredPolicies(sec string, ptype string, newRules [][

if e.shouldNotify() {
var err error
if watcher, ok := e.watcher.(persist.WatcherUpdatable); ok {
err = watcher.UpdateForUpdatePolicies(oldRules, newRules)
if watcher, ok := e.watcher.(persist.UpdatableWatcher); ok {
err = watcher.UpdateForUpdatePolicies(sec, ptype, oldRules, newRules)
} else {
err = e.watcher.Update()
}
Expand Down
4 changes: 2 additions & 2 deletions persist/file-adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ type Adapter struct {
filePath string
}

func (a *Adapter) UpdatePolicy(sec string, ptype string, oldRule, newPolicy []string) error {
func (a *Adapter) UpdatePolicy(sec string, ptype string, oldRule, newRule []string) error {
return errors.New("not implemented")
}

func (a *Adapter) UpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) error {
return errors.New("not implemented")
}

func (a *Adapter) UpdateFilteredPolicies(sec string, ptype string, newPolicies [][]string, fieldIndex int, fieldValues ...string) ([][]string, error) {
func (a *Adapter) UpdateFilteredPolicies(sec string, ptype string, newRules [][]string, fieldIndex int, fieldValues ...string) ([][]string, error) {
return nil, errors.New("not implemented")
}

Expand Down
4 changes: 2 additions & 2 deletions persist/update_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ 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
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, newPolicies [][]string, fieldIndex int, fieldValues ...string) ([][]string, error)
UpdateFilteredPolicies(sec string, ptype string, newRules [][]string, fieldIndex int, fieldValues ...string) ([][]string, error)
}
8 changes: 4 additions & 4 deletions persist/watcher_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

package persist

// WatcherUpdatable is the strengthen for Casbin watchers.
type WatcherUpdatable interface {
// UpdatableWatcher is strengthened for Casbin watchers.
type UpdatableWatcher 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
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(oldRules, newRules [][]string) error
UpdateForUpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) error
}
0