crowdsec/cmd/crowdsec-cli/config.go

62 lines
1.7 KiB
Go
Raw Normal View History

2020-05-15 09:39:16 +00:00
package main
import (
"fmt"
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
2020-05-15 09:39:16 +00:00
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)
/*CliCfg is the cli configuration structure, might be unexported*/
type cliConfig struct {
configured bool
2020-05-24 16:15:59 +00:00
ConfigFilePath string `yaml:"config_file"`
configFolder string
output string
HubFolder string `yaml:"hub_folder"`
2020-05-24 17:17:03 +00:00
InstallFolder string
2020-05-24 16:15:59 +00:00
BackendPluginFolder string `yaml:"backend_folder"`
DataFolder string `yaml:"data_folder"`
SimulationCfgPath string `yaml:"simulation_path,omitempty"`
SimulationCfg *csconfig.SimulationConfig
2020-05-15 09:39:16 +00:00
}
func NewConfigCmd() *cobra.Command {
var cmdConfig = &cobra.Command{
Use: "config [command] <value>",
Short: "Allows to view/edit cscli config",
Long: `Allow to configure database plugin path and installation directory.
2020-05-15 09:39:16 +00:00
If no commands are specified, config is in interactive mode.`,
Example: `- cscli config show
2020-05-15 09:39:16 +00:00
- cscli config prompt`,
Args: cobra.ExactArgs(1),
}
var cmdConfigShow = &cobra.Command{
Use: "show",
Short: "Displays current config",
Long: `Displays the current cli configuration.`,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
if config.output == "json" {
log.WithFields(log.Fields{
2020-05-24 16:15:59 +00:00
"crowdsec_configuration_file": config.ConfigFilePath,
"backend_folder": config.BackendPluginFolder,
"data_folder": config.DataFolder,
2020-05-15 09:39:16 +00:00
}).Warning("Current config")
} else {
x, err := yaml.Marshal(config)
if err != nil {
log.Fatalf("failed to marshal current configuration : %v", err)
}
fmt.Printf("%s", x)
}
},
}
cmdConfig.AddCommand(cmdConfigShow)
return cmdConfig
}