RemovePolicy removes a policy rule from the model. Deprecated: Using AddPoliciesWithAffected instead.
(sec string, ptype string, rule []string)
| 255 | // RemovePolicy removes a policy rule from the model. |
| 256 | // Deprecated: Using AddPoliciesWithAffected instead. |
| 257 | func (model Model) RemovePolicy(sec string, ptype string, rule []string) (bool, error) { |
| 258 | ast, err := model.GetAssertion(sec, ptype) |
| 259 | if err != nil { |
| 260 | return false, err |
| 261 | } |
| 262 | key := strings.Join(rule, DefaultSep) |
| 263 | index, ok := ast.PolicyMap[key] |
| 264 | if !ok { |
| 265 | return false, nil |
| 266 | } |
| 267 | |
| 268 | lastIdx := len(ast.Policy) - 1 |
| 269 | if index != lastIdx { |
| 270 | ast.Policy[index] = ast.Policy[lastIdx] |
| 271 | lastPolicyKey := strings.Join(ast.Policy[index], DefaultSep) |
| 272 | ast.PolicyMap[lastPolicyKey] = index |
| 273 | } |
| 274 | ast.Policy = ast.Policy[:lastIdx] |
| 275 | delete(ast.PolicyMap, key) |
| 276 | return true, nil |
| 277 | } |
| 278 | |
| 279 | // UpdatePolicy updates a policy rule from the model. |
| 280 | func (model Model) UpdatePolicy(sec string, ptype string, oldRule []string, newRule []string) (bool, error) { |
nothing calls this directly
no test coverage detected