mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-18 02:50:43 +02:00
fix: profilemanager panic when reading incomplete config (#4309)
fix: profilemanager panic when reading incomplete config (#4309)
This commit is contained in:
committed by
GitHub
parent
bef99d48f8
commit
0926400b8a
@@ -47,7 +47,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().StringVarP(&serviceName, "service", "s", defaultServiceName, "Netbird system service name")
|
rootCmd.PersistentFlags().StringVarP(&serviceName, "service", "s", defaultServiceName, "Netbird system service name")
|
||||||
serviceEnvDesc := `Sets extra environment variables for the service. ` +
|
serviceEnvDesc := `Sets extra environment variables for the service. ` +
|
||||||
`You can specify a comma-separated list of KEY=VALUE pairs. ` +
|
`You can specify a comma-separated list of KEY=VALUE pairs. ` +
|
||||||
`E.g. --service-env LOG_LEVEL=debug,CUSTOM_VAR=value`
|
`E.g. --service-env NB_LOG_LEVEL=debug,CUSTOM_VAR=value`
|
||||||
|
|
||||||
installCmd.Flags().StringSliceVar(&serviceEnvVars, "service-env", nil, serviceEnvDesc)
|
installCmd.Flags().StringSliceVar(&serviceEnvVars, "service-env", nil, serviceEnvDesc)
|
||||||
reconfigureCmd.Flags().StringSliceVar(&serviceEnvVars, "service-env", nil, serviceEnvDesc)
|
reconfigureCmd.Flags().StringSliceVar(&serviceEnvVars, "service-env", nil, serviceEnvDesc)
|
||||||
|
@@ -593,17 +593,9 @@ func update(input ConfigInput) (*Config, error) {
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetConfig read config file and return with Config. Errors out if it does not exist
|
||||||
func GetConfig(configPath string) (*Config, error) {
|
func GetConfig(configPath string) (*Config, error) {
|
||||||
if !fileExists(configPath) {
|
return readConfig(configPath, false)
|
||||||
return nil, fmt.Errorf("config file %s does not exist", configPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
config := &Config{}
|
|
||||||
if _, err := util.ReadJson(configPath, config); err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to read config file %s: %w", configPath, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateOldManagementURL checks whether client can switch to the new Management URL with port 443 and the management domain.
|
// UpdateOldManagementURL checks whether client can switch to the new Management URL with port 443 and the management domain.
|
||||||
@@ -695,6 +687,11 @@ func CreateInMemoryConfig(input ConfigInput) (*Config, error) {
|
|||||||
|
|
||||||
// ReadConfig read config file and return with Config. If it is not exists create a new with default values
|
// ReadConfig read config file and return with Config. If it is not exists create a new with default values
|
||||||
func ReadConfig(configPath string) (*Config, error) {
|
func ReadConfig(configPath string) (*Config, error) {
|
||||||
|
return readConfig(configPath, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadConfig read config file and return with Config. If it is not exists create a new with default values
|
||||||
|
func readConfig(configPath string, createIfMissing bool) (*Config, error) {
|
||||||
if fileExists(configPath) {
|
if fileExists(configPath) {
|
||||||
err := util.EnforcePermission(configPath)
|
err := util.EnforcePermission(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -715,6 +712,8 @@ func ReadConfig(configPath string) (*Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
|
} else if !createIfMissing {
|
||||||
|
return nil, fmt.Errorf("config file %s does not exist", configPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := createNewConfig(ConfigInput{ConfigPath: configPath})
|
cfg, err := createNewConfig(ConfigInput{ConfigPath: configPath})
|
||||||
|
Reference in New Issue
Block a user