()
| 319 | } |
| 320 | |
| 321 | func (model Model) SortPoliciesByPriority() error { |
| 322 | for ptype, assertion := range model["p"] { |
| 323 | priorityIndex, err := model.GetFieldIndex(ptype, constant.PriorityIndex) |
| 324 | if err != nil { |
| 325 | continue |
| 326 | } |
| 327 | policies := assertion.Policy |
| 328 | sort.SliceStable(policies, func(i, j int) bool { |
| 329 | p1, err := strconv.Atoi(policies[i][priorityIndex]) |
| 330 | if err != nil { |
| 331 | return true |
| 332 | } |
| 333 | p2, err := strconv.Atoi(policies[j][priorityIndex]) |
| 334 | if err != nil { |
| 335 | return true |
| 336 | } |
| 337 | return p1 < p2 |
| 338 | }) |
| 339 | for i, policy := range assertion.Policy { |
| 340 | assertion.PolicyMap[strings.Join(policy, ",")] = i |
| 341 | } |
| 342 | } |
| 343 | return nil |
| 344 | } |
| 345 | |
| 346 | var ( |
| 347 | pPattern = regexp.MustCompile("^p_") |
no test coverage detected