2022-03-17 12:19:23 -05:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
2022-03-17 12:19:23 -05:00
|
|
|
"github.com/grafana/grafana/pkg/web"
|
|
|
|
)
|
|
|
|
|
2022-10-21 15:48:32 -05:00
|
|
|
func GuessNameFromUID(uid string) string {
|
|
|
|
sidx := strings.LastIndex(uid, "/") + 1
|
|
|
|
didx := strings.LastIndex(uid, ".")
|
|
|
|
if didx > sidx && didx != sidx {
|
|
|
|
return uid[sidx:didx]
|
|
|
|
}
|
|
|
|
if sidx > 0 {
|
|
|
|
return uid[sidx:]
|
|
|
|
}
|
|
|
|
return uid
|
|
|
|
}
|
|
|
|
|
2022-03-17 12:19:23 -05:00
|
|
|
func splitFirstSegment(path string) (string, string) {
|
|
|
|
idx := strings.Index(path, "/")
|
|
|
|
if idx == 0 {
|
|
|
|
path = path[1:]
|
|
|
|
idx = strings.Index(path, "/")
|
|
|
|
}
|
|
|
|
|
|
|
|
if idx > 0 {
|
|
|
|
return path[:idx], path[idx+1:]
|
|
|
|
}
|
|
|
|
return path, ""
|
|
|
|
}
|
|
|
|
|
2023-01-27 01:50:36 -06:00
|
|
|
func getPathAndScope(c *contextmodel.ReqContext) (string, string) {
|
2022-03-17 12:19:23 -05:00
|
|
|
params := web.Params(c.Req)
|
|
|
|
path := params["*"]
|
|
|
|
if path == "" {
|
|
|
|
return "", ""
|
|
|
|
}
|
2022-07-07 06:32:18 -05:00
|
|
|
return splitFirstSegment(path)
|
2022-03-17 12:19:23 -05:00
|
|
|
}
|
2022-07-17 13:41:54 -05:00
|
|
|
|
|
|
|
func getFirstSegment(path string) string {
|
|
|
|
firstSegment, _ := splitFirstSegment(path)
|
|
|
|
return firstSegment
|
|
|
|
}
|