MCPcopy Index your code
hub / github.com/apache/casbin / addPolicy

Method addPolicy

internal_api.go:378–398  ·  view source on GitHub ↗

addPolicy adds a rule to the current policy.

(sec string, ptype string, rule []string)

Source from the content-addressed store, hash-verified

376
377// addPolicy adds a rule to the current policy.
378func (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

Callers 2

AddNamedPolicyMethod · 0.95

Calls 5

logPolicyOperationMethod · 0.95
shouldNotifyMethod · 0.95
UpdateForAddPolicyMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected