MCPcopy Index your code
hub / github.com/coder/coder / asserts

Function asserts

coderd/database/dbauthz/setup_test.go:554–588  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

552// ...
553// }
554func 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
590type emptyPreparedAuthorized struct{}
591

Callers 1

AssertsMethod · 0.85

Calls 2

ActionTypeAlias · 0.92
RBACObjectMethod · 0.65

Tested by

no test coverage detected