mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 10:22:30 +08: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:
@ -110,6 +110,12 @@ the group `foo`, set
|
|||||||
allowed_groups = example, foo/bar
|
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
|
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
|
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
|
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
|
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
|
### 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.
|
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.
|
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
|
### Example SAML configuration
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
@ -33,6 +34,16 @@ func SplitString(str string) []string {
|
|||||||
return []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, ",", " "))
|
return strings.Fields(strings.ReplaceAll(str, ",", " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +46,17 @@ func TestStringsFallback3(t *testing.T) {
|
|||||||
|
|
||||||
func TestSplitString(t *testing.T) {
|
func TestSplitString(t *testing.T) {
|
||||||
tests := map[string][]string{
|
tests := map[string][]string{
|
||||||
"": {},
|
"": {},
|
||||||
"test": {"test"},
|
"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"},
|
||||||
"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 {
|
for input, expected := range tests {
|
||||||
assert.EqualValues(t, expected, SplitString(input))
|
assert.EqualValues(t, expected, SplitString(input))
|
||||||
|
Reference in New Issue
Block a user