From a6b55f2b5eb5cc9067ed486abd58cade1b2abeff Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Fri, 13 Oct 2023 09:52:51 +0200 Subject: [PATCH] cscli config feeature-flags: point user to the right location of feature.yaml (#2539) --- cmd/crowdsec-cli/config_feature_flags.go | 11 ++++++++++- pkg/csconfig/fflag.go | 12 +++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd/crowdsec-cli/config_feature_flags.go b/cmd/crowdsec-cli/config_feature_flags.go index ed672711f..838d8a0c1 100644 --- a/cmd/crowdsec-cli/config_feature_flags.go +++ b/cmd/crowdsec-cli/config_feature_flags.go @@ -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_ to true") - fmt.Printf(" - add the line '- ' 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 '- ' to the file %s\n", featurePath) fmt.Println() if len(enabled) == 0 && len(disabled) == 0 { diff --git a/pkg/csconfig/fflag.go b/pkg/csconfig/fflag.go index 444585fb8..7311f9e75 100644 --- a/pkg/csconfig/fflag.go +++ b/pkg/csconfig/fflag.go @@ -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)