Strict configuration parsing (#3773)

* Test configuration loading more precisely

* Add strict configuration parsing
This commit is contained in:
Aarni Koskela
2023-11-16 09:42:49 +02:00
committed by GitHub
parent 184223cb2f
commit e8deb65c4b
11 changed files with 119 additions and 47 deletions

View File

@ -30,8 +30,9 @@ import (
)
var (
cfgFile string
showVersion bool
cfgFile string
showVersion bool
strictConfig bool
serverCfg v1.ServerConfig
)
@ -39,6 +40,7 @@ var (
func init() {
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file of frps")
rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "v", false, "version of frps")
rootCmd.PersistentFlags().BoolVarP(&strictConfig, "strict_config", "", false, "strict config parsing mode")
RegisterServerConfigFlags(rootCmd, &serverCfg)
}
@ -58,7 +60,7 @@ var rootCmd = &cobra.Command{
err error
)
if cfgFile != "" {
svrCfg, isLegacyFormat, err = config.LoadServerConfig(cfgFile)
svrCfg, isLegacyFormat, err = config.LoadServerConfig(cfgFile, strictConfig)
if err != nil {
fmt.Println(err)
os.Exit(1)

View File

@ -36,7 +36,7 @@ var verifyCmd = &cobra.Command{
fmt.Println("frps: the configuration file is not specified")
return nil
}
svrCfg, _, err := config.LoadServerConfig(cfgFile)
svrCfg, _, err := config.LoadServerConfig(cfgFile, strictConfig)
if err != nil {
fmt.Println(err)
os.Exit(1)