MCPcopy
hub / github.com/apache/casbin / SavePolicy

Method SavePolicy

enforcer.go:527–552  ·  view source on GitHub ↗

SavePolicy saves the current policy (usually after changed with Casbin API) back to file/database.

()

Source from the content-addressed store, hash-verified

525
526// SavePolicy saves the current policy (usually after changed with Casbin API) back to file/database.
527func (e *Enforcer) SavePolicy() error {
528 logEntry := e.onLogBeforeEventInSavePolicy()
529
530 if e.IsFiltered() {
531 err := errors.New("cannot save a filtered policy")
532 e.onLogAfterEventWithError(logEntry, err)
533 return err
534 }
535 if err := e.adapter.SavePolicy(e.model); err != nil {
536 e.onLogAfterEventWithError(logEntry, err)
537 return err
538 }
539
540 e.onLogAfterEventInSavePolicy(logEntry)
541
542 if e.watcher != nil {
543 var err error
544 if watcher, ok := e.watcher.(persist.WatcherEx); ok {
545 err = watcher.UpdateForSavePolicy(e.model)
546 } else {
547 err = e.watcher.Update()
548 }
549 return err
550 }
551 return nil
552}
553
554// getDomainTokens extracts domain token names from request and policy definitions.
555// Returns empty strings if tokens cannot be found.

Callers 8

TestSetWatcherExFunction · 0.95
TestSetWatcherFunction · 0.95
TestSavePolicyFunction · 0.95
TestLoadFilteredPolicyFunction · 0.95
TestNoErrorFunction · 0.95
TestSetWatcherUpdatableFunction · 0.95

Calls 7

IsFilteredMethod · 0.95
SavePolicyMethod · 0.65
UpdateForSavePolicyMethod · 0.65
UpdateMethod · 0.65

Tested by 8

TestSetWatcherExFunction · 0.76
TestSetWatcherFunction · 0.76
TestSavePolicyFunction · 0.76
TestLoadFilteredPolicyFunction · 0.76
TestNoErrorFunction · 0.76
TestSetWatcherUpdatableFunction · 0.76