2022-01-26 11:44:20 -06:00
|
|
|
package featuremgmt
|
|
|
|
|
|
|
|
import (
|
2022-08-10 08:37:51 -05:00
|
|
|
"os"
|
2022-01-26 11:44:20 -06:00
|
|
|
|
2022-12-06 14:17:17 -06:00
|
|
|
"gopkg.in/yaml.v3"
|
2022-01-26 11:44:20 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type configBody struct {
|
|
|
|
// define variables that can be used in expressions
|
2023-08-30 10:46:47 -05:00
|
|
|
Vars map[string]any `yaml:"vars"`
|
2022-01-26 11:44:20 -06:00
|
|
|
|
|
|
|
// 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
|
2022-08-10 08:37:51 -05:00
|
|
|
yamlFile, err := os.ReadFile(filename)
|
2022-01-26 11:44:20 -06:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = yaml.Unmarshal(yamlFile, cfg)
|
|
|
|
cfg.filename = filename
|
|
|
|
return cfg, err
|
|
|
|
}
|