mirror of https://github.com/grafana/grafana
FeatureFlags: Remove the unsupported/undocumented option to read flags from a file (#79959)
parent
68d4e8a930
commit
48a5c1e850
@ -1,34 +0,0 @@ |
|||||||
package featuremgmt |
|
||||||
|
|
||||||
import ( |
|
||||||
"os" |
|
||||||
|
|
||||||
"gopkg.in/yaml.v3" |
|
||||||
) |
|
||||||
|
|
||||||
type configBody struct { |
|
||||||
// define variables that can be used in expressions
|
|
||||||
Vars map[string]any `yaml:"vars"` |
|
||||||
|
|
||||||
// Define and override feature flag properties
|
|
||||||
Flags []FeatureFlag `yaml:"flags"` |
|
||||||
|
|
||||||
// keep track of where the fie was loaded from
|
|
||||||
filename string |
|
||||||
} |
|
||||||
|
|
||||||
// will read a single configfile
|
|
||||||
func readConfigFile(filename string) (*configBody, error) { |
|
||||||
cfg := &configBody{} |
|
||||||
|
|
||||||
// Can ignore gosec G304 because the file path is forced within config subfolder
|
|
||||||
//nolint:gosec
|
|
||||||
yamlFile, err := os.ReadFile(filename) |
|
||||||
if err != nil { |
|
||||||
return cfg, err |
|
||||||
} |
|
||||||
|
|
||||||
err = yaml.Unmarshal(yamlFile, cfg) |
|
||||||
cfg.filename = filename |
|
||||||
return cfg, err |
|
||||||
} |
|
@ -1,25 +0,0 @@ |
|||||||
package featuremgmt |
|
||||||
|
|
||||||
import ( |
|
||||||
"fmt" |
|
||||||
"testing" |
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert" |
|
||||||
"github.com/stretchr/testify/require" |
|
||||||
"gopkg.in/yaml.v3" |
|
||||||
) |
|
||||||
|
|
||||||
func TestReadingFeatureSettings(t *testing.T) { |
|
||||||
config, err := readConfigFile("testdata/features.yaml") |
|
||||||
require.NoError(t, err, "No error when reading feature configs") |
|
||||||
|
|
||||||
assert.Equal(t, map[string]any{ |
|
||||||
"level": "free", |
|
||||||
"stack": "something", |
|
||||||
"valA": "value from features.yaml", |
|
||||||
}, config.Vars) |
|
||||||
|
|
||||||
out, err := yaml.Marshal(config) |
|
||||||
require.NoError(t, err) |
|
||||||
fmt.Printf("%s", string(out)) |
|
||||||
} |
|
@ -1,33 +0,0 @@ |
|||||||
include: |
|
||||||
- included.yaml # not yet supported |
|
||||||
|
|
||||||
vars: |
|
||||||
stack: something |
|
||||||
level: free |
|
||||||
valA: value from features.yaml |
|
||||||
|
|
||||||
flags: |
|
||||||
- name: feature1 |
|
||||||
description: feature1 |
|
||||||
expression: "false" |
|
||||||
|
|
||||||
- name: feature3 |
|
||||||
description: feature3 |
|
||||||
expression: "true" |
|
||||||
|
|
||||||
- name: feature3 |
|
||||||
description: feature3 |
|
||||||
expression: env.level == 'free' |
|
||||||
|
|
||||||
- name: displaySwedishTheme |
|
||||||
description: enable swedish background theme |
|
||||||
expression: | |
|
||||||
// restrict to users allowing swedish language |
|
||||||
req.locale.contains("sv") |
|
||||||
- name: displayFrenchFlag |
|
||||||
description: sho background theme |
|
||||||
expression: | |
|
||||||
// only admins |
|
||||||
user.id == 1 |
|
||||||
// show to users allowing french language |
|
||||||
&& req.locale.contains("fr") |
|
@ -1,13 +0,0 @@ |
|||||||
include: |
|
||||||
- features.yaml # make sure we avoid recusion! |
|
||||||
|
|
||||||
# variables that can be used in expressions |
|
||||||
vars: |
|
||||||
stack: something |
|
||||||
deep: 1 |
|
||||||
valA: value from included.yaml |
|
||||||
|
|
||||||
flags: |
|
||||||
- name: featureFromIncludedFile |
|
||||||
description: an inlcuded file |
|
||||||
expression: invalid expression string here |
|
Loading…
Reference in new issue