[release-11.5.2] IAM: log error when malformed json arrays are found in SSO configs (#100649)

IAM: Log error when malformed json arrays are found in SSO configs (#99896)

(cherry picked from commit eeadb7e771)
This commit is contained in:
grafana-delivery-bot[bot]
2025-02-13 18:37:38 +01:00
committed by GitHub
parent 327ca47f51
commit 6c3e9e5976
11 changed files with 128 additions and 30 deletions
+13 -4
View File
@@ -33,9 +33,18 @@ func stringsFallback(vals ...string) string {
// SplitString splits a string and returns a list of strings. It supports JSON list syntax and strings separated by commas or spaces.
// It supports quoted strings with spaces, e.g. "foo bar", "baz".
// It will return an empty list if it fails to parse the string.
func SplitString(str string) []string {
result, _ := SplitStringWithError(str)
return result
}
// SplitStringWithError splits a string and returns a list of strings. It supports JSON list syntax and strings separated by commas or spaces.
// It supports quoted strings with spaces, e.g. "foo bar", "baz".
// It returns an error if it cannot parse the string.
func SplitStringWithError(str string) ([]string, error) {
if len(str) == 0 {
return []string{}
return []string{}, nil
}
// JSON list syntax support
@@ -43,9 +52,9 @@ func SplitString(str string) []string {
var res []string
err := json.Unmarshal([]byte(str), &res)
if err != nil {
return []string{}
return []string{}, fmt.Errorf("incorrect format: %s", str)
}
return res
return res, nil
}
matches := stringListItemMatcher.FindAllString(str, -1)
@@ -55,7 +64,7 @@ func SplitString(str string) []string {
result[i] = strings.Trim(match, "\"")
}
return result
return result, nil
}
// GetAgeString returns a string representing certain time from years to minutes.