cscli config feeature-flags: point user to the right location of feature.yaml (#2539)
This commit is contained in:
parent
a254b436c7
commit
a6b55f2b5e
2 changed files with 19 additions and 4 deletions
|
@ -2,10 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/fflag"
|
||||
)
|
||||
|
||||
|
@ -87,7 +89,14 @@ func runConfigFeatureFlags(cmd *cobra.Command, args []string) error {
|
|||
|
||||
fmt.Println("To enable a feature you can: ")
|
||||
fmt.Println(" - set the environment variable CROWDSEC_FEATURE_<uppercase_feature_name> to true")
|
||||
fmt.Printf(" - add the line '- <feature_name>' to the file %s/feature.yaml\n", csConfig.ConfigPaths.ConfigDir)
|
||||
|
||||
featurePath, err := filepath.Abs(csconfig.GetFeatureFilePath(ConfigFilePath))
|
||||
if err != nil {
|
||||
// we already read the file, shouldn't happen
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf(" - add the line '- <feature_name>' to the file %s\n", featurePath)
|
||||
fmt.Println()
|
||||
|
||||
if len(enabled) == 0 && len(disabled) == 0 {
|
||||
|
|
|
@ -18,12 +18,18 @@ func LoadFeatureFlagsEnv(logger *log.Logger) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadFeatureFlags parses feature.yaml to enable feature flags.
|
||||
// FeatureFlagsFileLocation returns the path to the feature.yaml file.
|
||||
// The file is in the same directory as config.yaml, which is provided
|
||||
// as the fist parameter. This can be different than ConfigPaths.ConfigDir
|
||||
func LoadFeatureFlagsFile(configPath string, logger *log.Logger) error {
|
||||
// because we have not read config.yaml yet so we don't know the value of ConfigDir.
|
||||
func GetFeatureFilePath(configPath string) string {
|
||||
dir := filepath.Dir(configPath)
|
||||
featurePath := filepath.Join(dir, "feature.yaml")
|
||||
return filepath.Join(dir, "feature.yaml")
|
||||
}
|
||||
|
||||
// LoadFeatureFlags parses feature.yaml to enable feature flags.
|
||||
func LoadFeatureFlagsFile(configPath string, logger *log.Logger) error {
|
||||
featurePath := GetFeatureFilePath(configPath)
|
||||
|
||||
if err := fflag.Crowdsec.SetFromYamlFile(featurePath, logger); err != nil {
|
||||
return fmt.Errorf("file %s: %s", featurePath, err)
|
||||
|
|
Loading…
Reference in a new issue