github.com/crowdsecurity/crowdsec@v1.6.1/pkg/csconfig/fflag.go (about)

     1  package csconfig
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  	"strings"
     7  
     8  	log "github.com/sirupsen/logrus"
     9  
    10  	"github.com/crowdsecurity/crowdsec/pkg/fflag"
    11  )
    12  
    13  // LoadFeatureFlagsEnv parses the environment variables to enable feature flags.
    14  func LoadFeatureFlagsEnv(logger *log.Logger) error {
    15  	if err := fflag.Crowdsec.SetFromEnv(logger); err != nil {
    16  		return err
    17  	}
    18  	return nil
    19  }
    20  
    21  // FeatureFlagsFileLocation returns the path to the feature.yaml file.
    22  // The file is in the same directory as config.yaml, which is provided
    23  // as the fist parameter. This can be different than ConfigPaths.ConfigDir
    24  // because we have not read config.yaml yet so we don't know the value of ConfigDir.
    25  func GetFeatureFilePath(configPath string) string {
    26  	dir := filepath.Dir(configPath)
    27  	return filepath.Join(dir, "feature.yaml")
    28  }
    29  
    30  // LoadFeatureFlags parses feature.yaml to enable feature flags.
    31  func LoadFeatureFlagsFile(configPath string, logger *log.Logger) error {
    32  	featurePath := GetFeatureFilePath(configPath)
    33  
    34  	if err := fflag.Crowdsec.SetFromYamlFile(featurePath, logger); err != nil {
    35  		return fmt.Errorf("file %s: %s", featurePath, err)
    36  	}
    37  	return nil
    38  }
    39  
    40  // ListFeatureFlags returns a list of the enabled feature flags.
    41  func ListFeatureFlags() string {
    42  	enabledFeatures := fflag.Crowdsec.GetEnabledFeatures()
    43  
    44  	msg := "<none>"
    45  	if len(enabledFeatures) > 0 {
    46  		msg = strings.Join(enabledFeatures, ", ")
    47  	}
    48  
    49  	return msg
    50  }