RBAC: Permission check performance improvements for the new search (#60729)

* Add checker and update the resource filter function for new search

* Add tests for checker

* small fixes

* handle location for panels correctly

* clean up checker code and extend the tests for it

* more fixes, but tests don't quite work yet

* a small change to return error

* cleanup

* more simplification

* fix tests

* correct wrong argument ordering & use constant

* Apply suggestions from code review

Co-authored-by: Artur Wierzbicki <artur.wierzbicki@grafana.com>

* import

* check general folder from permission checker function

* handle root folder aka general folder properly

* update tests

* clean up

* lint

* add fix from main

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
Co-authored-by: Artur Wierzbicki <artur.wierzbicki@grafana.com>
This commit is contained in:
Ieva
2023-01-27 12:12:30 +00:00
committed by GitHub
co-authored by Artur Wierzbicki Karl Persson
parent dab3fac01b
commit eb9ef34272
27 changed files with 289 additions and 119 deletions
+16 -9
View File
@@ -142,19 +142,26 @@ func (s scopeProviderImpl) GetResourceAllIDScope() string {
return GetResourceAllIDScope(s.root)
}
// WildcardsFromPrefix generates valid wildcards from prefix
// datasource:uid: => "*", "datasource:*", "datasource:uid:*"
func WildcardsFromPrefix(prefix string) Wildcards {
return WildcardsFromPrefixes([]string{prefix})
}
// WildcardsFromPrefixes generates valid wildcards from prefixes
// datasource:uid: => "*", "datasource:*", "datasource:uid:*"
func WildcardsFromPrefixes(prefixes []string) Wildcards {
var b strings.Builder
wildcards := Wildcards{"*"}
parts := strings.Split(prefix, ":")
for _, p := range parts {
if p == "" {
continue
for _, prefix := range prefixes {
parts := strings.Split(prefix, ":")
for _, p := range parts {
if p == "" {
continue
}
b.WriteString(p)
b.WriteRune(':')
wildcards = append(wildcards, b.String()+"*")
}
b.WriteString(p)
b.WriteRune(':')
wildcards = append(wildcards, b.String()+"*")
b.Reset()
}
return wildcards
}