UpdatePolicySelf provides a method for dispatcher to update an authorization rule from the current policy.
(shouldPersist func() bool, sec string, ptype string, oldRule, newRule []string)
| 138 | |
| 139 | // UpdatePolicySelf provides a method for dispatcher to update an authorization rule from the current policy. |
| 140 | func (d *DistributedEnforcer) UpdatePolicySelf(shouldPersist func() bool, sec string, ptype string, oldRule, newRule []string) (affected bool, err error) { |
| 141 | d.m.Lock() |
| 142 | defer d.m.Unlock() |
| 143 | if shouldPersist != nil && shouldPersist() { |
| 144 | err = d.adapter.(persist.UpdatableAdapter).UpdatePolicy(sec, ptype, oldRule, newRule) |
| 145 | if err != nil { |
| 146 | return false, err |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | ruleUpdated, err := d.model.UpdatePolicy(sec, ptype, oldRule, newRule) |
| 151 | if !ruleUpdated || err != nil { |
| 152 | return ruleUpdated, err |
| 153 | } |
| 154 | |
| 155 | if sec == "g" { |
| 156 | err := d.BuildIncrementalRoleLinks(model.PolicyRemove, ptype, [][]string{oldRule}) // remove the old rule |
| 157 | if err != nil { |
| 158 | return ruleUpdated, err |
| 159 | } |
| 160 | err = d.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, [][]string{newRule}) // add the new rule |
| 161 | if err != nil { |
| 162 | return ruleUpdated, err |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return ruleUpdated, nil |
| 167 | } |
| 168 | |
| 169 | // UpdatePoliciesSelf provides a method for dispatcher to update a set of authorization rules from the current policy. |
| 170 | func (d *DistributedEnforcer) UpdatePoliciesSelf(shouldPersist func() bool, sec string, ptype string, oldRules, newRules [][]string) (affected bool, err error) { |
nothing calls this directly
no test coverage detected