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

Method LoadPolicy

enforcer.go:363–386  ·  view source on GitHub ↗

LoadPolicy reloads the policy from file/database.

()

Source from the content-addressed store, hash-verified

361
362// LoadPolicy reloads the policy from file/database.
363func (e *Enforcer) LoadPolicy() error {
364 logEntry := e.onLogBeforeEventInLoadPolicy()
365
366 newModel, err := e.loadPolicyFromAdapter(e.model)
367 if err != nil {
368 e.onLogAfterEventWithError(logEntry, err)
369 return err
370 }
371 err = e.applyModifiedModel(newModel)
372 if err != nil {
373 e.onLogAfterEventWithError(logEntry, err)
374 return err
375 }
376
377 e.onLogAfterEventInLoadPolicy(logEntry, newModel)
378
379 // Run detectors after all policy rules are loaded
380 err = e.RunDetections()
381 if err != nil {
382 return err
383 }
384
385 return nil
386}
387
388func (e *Enforcer) loadPolicyFromAdapter(baseModel model.Model) (model.Model, error) {
389 newModel := baseModel.Copy()

Callers 15

TestSetEventTypesFunction · 0.95
TestReloadPolicyFunction · 0.95
TestEnableAutoSaveFunction · 0.95
TestSetAdapterFromFileFunction · 0.95
TestInitEmptyFunction · 0.95
TestFailedToLoadPolicyFunction · 0.95
TestReloadPolicyWithFuncFunction · 0.95
TestCustomizedFieldIndexFunction · 0.95
TestLoadFilteredPolicyFunction · 0.95

Calls 6

loadPolicyFromAdapterMethod · 0.95
applyModifiedModelMethod · 0.95
RunDetectionsMethod · 0.95

Tested by 15

TestSetEventTypesFunction · 0.76
TestReloadPolicyFunction · 0.76
TestEnableAutoSaveFunction · 0.76
TestSetAdapterFromFileFunction · 0.76
TestInitEmptyFunction · 0.76
TestFailedToLoadPolicyFunction · 0.76
TestReloadPolicyWithFuncFunction · 0.76
TestCustomizedFieldIndexFunction · 0.76
TestLoadFilteredPolicyFunction · 0.76