asserts is a convenience method for creating AssertRBACs. The number of inputs must be an even number. asserts() will panic if this is not the case. Even-numbered inputs are the objects, and odd-numbered inputs are the actions. Objects must implement rbac.Objecter. Inputs can be a single policy.Ac
(inputs ...any)
| 552 | // ... |
| 553 | // } |
| 554 | func asserts(inputs ...any) []AssertRBAC { |
| 555 | if len(inputs)%2 != 0 { |
| 556 | panic(fmt.Sprintf("Must be an even length number of args, found %d", len(inputs))) |
| 557 | } |
| 558 | |
| 559 | out := make([]AssertRBAC, 0) |
| 560 | for i := 0; i < len(inputs); i += 2 { |
| 561 | obj, ok := inputs[i].(rbac.Objecter) |
| 562 | if !ok { |
| 563 | panic(fmt.Sprintf("object type '%T' does not implement rbac.Objecter", inputs[i])) |
| 564 | } |
| 565 | rbacObj := obj.RBACObject() |
| 566 | |
| 567 | var actions []policy.Action |
| 568 | actions, ok = inputs[i+1].([]policy.Action) |
| 569 | if !ok { |
| 570 | action, ok := inputs[i+1].(policy.Action) |
| 571 | if !ok { |
| 572 | // Could be the string type. |
| 573 | actionAsString, ok := inputs[i+1].(string) |
| 574 | if !ok { |
| 575 | panic(fmt.Sprintf("action '%T' not a supported action", inputs[i+1])) |
| 576 | } |
| 577 | action = policy.Action(actionAsString) |
| 578 | } |
| 579 | actions = []policy.Action{action} |
| 580 | } |
| 581 | |
| 582 | out = append(out, AssertRBAC{ |
| 583 | Object: rbacObj, |
| 584 | Actions: actions, |
| 585 | }) |
| 586 | } |
| 587 | return out |
| 588 | } |
| 589 | |
| 590 | type emptyPreparedAuthorized struct{} |
| 591 |
no test coverage detected