mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* add a more flexible way to create permissions * update interface for accesscontrol to use new eval interface * use new eval interface * update middleware to use new eval interface * remove evaluator function and move metrics to service * add tests for accesscontrol middleware * Remove failed function from interface and update inejct to create a new evaluator * Change name * Support Several sopes for a permission * use evaluator and update fakeAccessControl * Implement String that will return string representation of permissions for an evaluator Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com> Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
26 lines
501 B
Go
26 lines
501 B
Go
package accesscontrol
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Scope builds scope from parts
|
|
// e.g. Scope("users", "*") return "users:*"
|
|
func Scope(parts ...string) string {
|
|
b := strings.Builder{}
|
|
for i, c := range parts {
|
|
if i != 0 {
|
|
b.WriteRune(':')
|
|
}
|
|
b.WriteString(c)
|
|
}
|
|
return b.String()
|
|
}
|
|
|
|
// Parameter returns injectable scope part
|
|
// e.g. Scope("users", Parameter(":id")) or "users:" + Parameter(":id")
|
|
func Parameter(key string) string {
|
|
return fmt.Sprintf(`{{ index . "%s" }}`, key)
|
|
}
|