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

Method GetFilteredPolicy

model/policy.go:120–142  ·  view source on GitHub ↗

GetFilteredPolicy gets rules based on field filters from a policy.

(sec string, ptype string, fieldIndex int, fieldValues ...string)

Source from the content-addressed store, hash-verified

118
119// GetFilteredPolicy gets rules based on field filters from a policy.
120func (model Model) GetFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) ([][]string, error) {
121 _, err := model.GetAssertion(sec, ptype)
122 if err != nil {
123 return nil, err
124 }
125 res := [][]string{}
126
127 for _, rule := range model[sec][ptype].Policy {
128 matched := true
129 for i, fieldValue := range fieldValues {
130 if fieldValue != "" && rule[fieldIndex+i] != fieldValue {
131 matched = false
132 break
133 }
134 }
135
136 if matched {
137 res = append(res, rule)
138 }
139 }
140
141 return res, nil
142}
143
144// HasPolicyEx determines whether a model has the specified policy rule with error.
145func (model Model) HasPolicyEx(sec string, ptype string, rule []string) (bool, error) {

Callers

nothing calls this directly

Calls 1

GetAssertionMethod · 0.95

Tested by

no test coverage detected