GetFilteredPolicy gets rules based on field filters from a policy.
(sec string, ptype string, fieldIndex int, fieldValues ...string)
| 118 | |
| 119 | // GetFilteredPolicy gets rules based on field filters from a policy. |
| 120 | func (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. |
| 145 | func (model Model) HasPolicyEx(sec string, ptype string, rule []string) (bool, error) { |
nothing calls this directly
no test coverage detected