mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Config: Support JSON list syntax (#61288)
* Config: Separate lists either by spaces or by commas. * Simplify space separation * use separate function for the config strings * Change behavior only if string contains quotes * add test for invalid string * Use JSON list syntax * ignore leading spaces when process list * Add notes about using JSON lists into the docs * Fix typo * Apply suggestions from code review Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com> Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
This commit is contained in:
parent
045a12047f
commit
997105c20d
@ -110,6 +110,12 @@ the group `foo`, set
|
||||
allowed_groups = example, foo/bar
|
||||
```
|
||||
|
||||
To put values containing spaces in the list, use the following JSON syntax:
|
||||
|
||||
```ini
|
||||
allowed_groups = ["Admins", "Software Engineers"]
|
||||
```
|
||||
|
||||
Note that in GitLab, the group or subgroup name doesn't always match its
|
||||
display name, especially if the display name contains spaces or special
|
||||
characters. Make sure you always use the group or subgroup name as it appears
|
||||
|
@ -81,6 +81,12 @@ The `allowed_domains` option limits access to the users belonging to the specifi
|
||||
allowed_domains = mycompany.com mycompany.org
|
||||
```
|
||||
|
||||
To put values containing spaces in the list, use the following JSON syntax:
|
||||
|
||||
```ini
|
||||
allowed_groups = ["Admins", "Software Engineers"]
|
||||
```
|
||||
|
||||
### Map roles
|
||||
|
||||
Grafana can attempt to do role mapping through Okta OAuth. In order to achieve this, Grafana checks for the presence of a role using the [JMESPath](http://jmespath.org/examples.html) specified via the `role_attribute_path` configuration option.
|
||||
|
@ -390,6 +390,12 @@ You can use `*` as the Grafana organization in the mapping if you want all users
|
||||
|
||||
With the [`allowed_organizations`]({{< relref "../../../configure-grafana/enterprise-configuration/#allowed-organizations" >}}) option you can specify a list of organizations where the user must be a member of at least one of them to be able to log in to Grafana.
|
||||
|
||||
To put values containing spaces in the list, use the following JSON syntax:
|
||||
|
||||
```ini
|
||||
allowed_organizations = ["org 1", "second org"]
|
||||
```
|
||||
|
||||
### Example SAML configuration
|
||||
|
||||
```bash
|
||||
|
@ -1,6 +1,7 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
@ -33,6 +34,16 @@ func SplitString(str string) []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
// JSON list syntax support
|
||||
if strings.Index(strings.TrimSpace(str), "[") == 0 {
|
||||
var res []string
|
||||
err := json.Unmarshal([]byte(str), &res)
|
||||
if err != nil {
|
||||
return []string{}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
return strings.Fields(strings.ReplaceAll(str, ",", " "))
|
||||
}
|
||||
|
||||
|
@ -46,12 +46,17 @@ func TestStringsFallback3(t *testing.T) {
|
||||
|
||||
func TestSplitString(t *testing.T) {
|
||||
tests := map[string][]string{
|
||||
"": {},
|
||||
"test": {"test"},
|
||||
"test1 test2 test3": {"test1", "test2", "test3"},
|
||||
"test1,test2,test3": {"test1", "test2", "test3"},
|
||||
"test1, test2, test3": {"test1", "test2", "test3"},
|
||||
"test1 , test2 test3": {"test1", "test2", "test3"},
|
||||
"": {},
|
||||
"test": {"test"},
|
||||
" test1 test2 test3": {"test1", "test2", "test3"},
|
||||
"test1,test2,test3": {"test1", "test2", "test3"},
|
||||
"test1, test2, test3": {"test1", "test2", "test3"},
|
||||
"test1 , test2 test3": {"test1", "test2", "test3"},
|
||||
"foo, bar baz": {"foo", "bar", "baz"},
|
||||
`["foo", "bar baz"]`: {"foo", "bar baz"},
|
||||
`["foo", "bar \"baz\""]`: {"foo", "bar \"baz\""},
|
||||
` ["foo", "bar baz"]`: {"foo", "bar baz"},
|
||||
`[]`: {},
|
||||
}
|
||||
for input, expected := range tests {
|
||||
assert.EqualValues(t, expected, SplitString(input))
|
||||
|
Loading…
Reference in New Issue
Block a user