addPolicy adds a rule to the current policy.
(sec string, ptype string, rule []string)
| 376 | |
| 377 | // addPolicy adds a rule to the current policy. |
| 378 | func (e *Enforcer) addPolicy(sec string, ptype string, rule []string) (bool, error) { |
| 379 | ok, err := e.logPolicyOperation(log.EventAddPolicy, sec, rule, func() (bool, error) { |
| 380 | return e.addPolicyWithoutNotify(sec, ptype, rule) |
| 381 | }) |
| 382 | |
| 383 | if !ok || err != nil { |
| 384 | return ok, err |
| 385 | } |
| 386 | |
| 387 | if e.shouldNotify() { |
| 388 | var notifyErr error |
| 389 | if watcher, isWatcherEx := e.watcher.(persist.WatcherEx); isWatcherEx { |
| 390 | notifyErr = watcher.UpdateForAddPolicy(sec, ptype, rule...) |
| 391 | } else { |
| 392 | notifyErr = e.watcher.Update() |
| 393 | } |
| 394 | return true, notifyErr |
| 395 | } |
| 396 | |
| 397 | return true, nil |
| 398 | } |
| 399 | |
| 400 | // addPolicies adds rules to the current policy. |
| 401 | // If autoRemoveRepeat == true, existing rules are automatically filtered |
no test coverage detected