UpdatePolicy updates a policy rule from the model.
(sec string, ptype string, oldRule []string, newRule []string)
| 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) { |
| 281 | _, err := model.GetAssertion(sec, ptype) |
| 282 | if err != nil { |
| 283 | return false, err |
| 284 | } |
| 285 | oldPolicy := strings.Join(oldRule, DefaultSep) |
| 286 | index, ok := model[sec][ptype].PolicyMap[oldPolicy] |
| 287 | if !ok { |
| 288 | return false, nil |
| 289 | } |
| 290 | |
| 291 | model[sec][ptype].Policy[index] = newRule |
| 292 | delete(model[sec][ptype].PolicyMap, oldPolicy) |
| 293 | model[sec][ptype].PolicyMap[strings.Join(newRule, DefaultSep)] = index |
| 294 | |
| 295 | return true, nil |
| 296 | } |
| 297 | |
| 298 | // UpdatePolicies updates a policy rule from the model. |
| 299 | func (model Model) UpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) (bool, error) { |
nothing calls this directly
no test coverage detected