Migrate wrong datasource UIDs (#86598)
This commit is contained in:
@@ -30,7 +30,9 @@ var (
|
||||
var mtx sync.Mutex
|
||||
|
||||
// Legacy UID pattern
|
||||
var validUIDPattern = regexp.MustCompile(`^[a-zA-Z0-9\-\_]*$`).MatchString
|
||||
var validUIDCharPattern = `a-zA-Z0-9\-\_`
|
||||
var validUIDPattern = regexp.MustCompile(`^[` + validUIDCharPattern + `]*$`).MatchString
|
||||
var validUIDReplacer = regexp.MustCompile(`[^` + validUIDCharPattern + `]`).ReplaceAllString
|
||||
|
||||
// IsValidShortUID checks if short unique identifier contains valid characters
|
||||
// NOTE: future Grafana UIDs will need conform to https://github.com/kubernetes/apimachinery/blob/master/pkg/util/validation/validation.go#L43
|
||||
@@ -91,3 +93,13 @@ func ValidateUID(uid string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func AutofixUID(uid string) string {
|
||||
if IsShortUIDTooLong(uid) {
|
||||
return uid[:MaxUIDLength]
|
||||
}
|
||||
if !IsValidShortUID(uid) {
|
||||
uid = validUIDReplacer(uid, "-")
|
||||
}
|
||||
return uid
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user