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

Method SavePolicy

persist/string-adapter/adapter.go:57–76  ·  view source on GitHub ↗

SavePolicy saves all policy rules to the storage.

(model model.Model)

Source from the content-addressed store, hash-verified

55
56// SavePolicy saves all policy rules to the storage.
57func (a *Adapter) SavePolicy(model model.Model) error {
58 var tmp bytes.Buffer
59 for ptype, ast := range model["p"] {
60 for _, rule := range ast.Policy {
61 tmp.WriteString(ptype + ", ")
62 tmp.WriteString(util.ArrayToString(rule))
63 tmp.WriteString("\n")
64 }
65 }
66
67 for ptype, ast := range model["g"] {
68 for _, rule := range ast.Policy {
69 tmp.WriteString(ptype + ", ")
70 tmp.WriteString(util.ArrayToString(rule))
71 tmp.WriteString("\n")
72 }
73 }
74 a.Line = strings.TrimRight(tmp.String(), "\n")
75 return nil
76}
77
78// AddPolicy adds a policy rule to the storage.
79func (a *Adapter) AddPolicy(sec string, ptype string, rule []string) error {

Callers 1

SavePolicyCtxMethod · 0.95

Implementers 6

MockTransactionalAdaptertransaction_test.go
Enforcerenforcer.go
SyncedEnforcerenforcer_synced.go
Adapterpersist/file-adapter/adapter.go
AdapterMockpersist/file-adapter/adapter_mock.go
Adapterpersist/string-adapter/adapter.go

Calls 2

ArrayToStringFunction · 0.92
StringMethod · 0.65

Tested by

no test coverage detected