RBAC: Add scope resolvers for dashboards (#50110)

* Inject access control into dashboard service

* Add function to parse id scopes

* Add dashboard as return value

* Update mock

* Return only err to keep service interface

* Add scope resolvers for dashboard id scopes

* Add function to parse uid scopes

* Add dashboard uid scope resolver

* Register scope resolvers for dashboards

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
This commit is contained in:
Karl Persson
2022-06-07 11:02:20 +02:00
committed by GitHub
co-authored by Gabriel MABILLE
parent 9f6afb3475
commit c4a75f9eb3
19 changed files with 298 additions and 97 deletions
+21
View File
@@ -2,6 +2,7 @@ package accesscontrol
import (
"fmt"
"strconv"
"strings"
)
@@ -9,6 +10,26 @@ const (
maxPrefixParts = 2
)
func ParseScopeID(scope string) (int64, error) {
id, err := strconv.ParseInt(ScopeSuffix(scope), 10, 64)
if err != nil {
return 0, ErrInvalidScope
}
return id, nil
}
func ParseScopeUID(scope string) (string, error) {
uid := ScopeSuffix(scope)
if len(uid) == 0 {
return "", ErrInvalidScope
}
return uid, nil
}
func ScopeSuffix(scope string) string {
return scope[len(ScopePrefix(scope)):]
}
func GetResourceScope(resource string, resourceID string) string {
return Scope(resource, "id", resourceID)
}