mirror of
https://github.com/popura-network/Popura.git
synced 2024-12-06 19:26:23 +01:00
Fix empty values serialization
This commit is contained in:
@@ -107,13 +107,13 @@ func run_yggdrasil() {
|
||||
// their configuration file with newly mapped names (like above) or to
|
||||
// convert from plain JSON to commented HJSON.
|
||||
if *normaliseconf {
|
||||
fmt.Println(popura.SaveConfig(yggConfig, popConfig, *confjson))
|
||||
fmt.Println(popura.SaveConfig(*yggConfig, *popConfig, *confjson))
|
||||
return
|
||||
}
|
||||
case *genconf:
|
||||
// Generate a new configuration and print it to stdout.
|
||||
yggConfig, popConfig = popura.GenerateConfig()
|
||||
fmt.Println(popura.SaveConfig(yggConfig, popConfig, *confjson))
|
||||
fmt.Println(popura.SaveConfig(*yggConfig, *popConfig, *confjson))
|
||||
return
|
||||
default:
|
||||
// No flags were provided, therefore print the list of flags to stdout.
|
||||
|
||||
+29
-3
@@ -26,13 +26,39 @@ func GenerateConfig() (*config.NodeConfig, *PopuraConfig) {
|
||||
return config.GenerateConfig(), &popConfig
|
||||
}
|
||||
|
||||
func SaveConfig(yggConfig *config.NodeConfig, popConfig *PopuraConfig, isjson bool) string {
|
||||
// initialize empty values for correct JSON serialization
|
||||
func correctEmptyValues(yggConfig *config.NodeConfig) {
|
||||
if len(yggConfig.TunnelRouting.IPv4LocalSubnets) == 0 {
|
||||
yggConfig.TunnelRouting.IPv4LocalSubnets = []string{}
|
||||
}
|
||||
if len(yggConfig.TunnelRouting.IPv6LocalSubnets) == 0 {
|
||||
yggConfig.TunnelRouting.IPv6LocalSubnets = []string{}
|
||||
}
|
||||
if len(yggConfig.TunnelRouting.IPv4RemoteSubnets) == 0 {
|
||||
yggConfig.TunnelRouting.IPv4RemoteSubnets = make(map[string]string)
|
||||
}
|
||||
if len(yggConfig.TunnelRouting.IPv6RemoteSubnets) == 0 {
|
||||
yggConfig.TunnelRouting.IPv6RemoteSubnets = make(map[string]string)
|
||||
}
|
||||
if len(yggConfig.SessionFirewall.WhitelistEncryptionPublicKeys) == 0 {
|
||||
yggConfig.SessionFirewall.WhitelistEncryptionPublicKeys = []string{}
|
||||
}
|
||||
if len(yggConfig.SessionFirewall.BlacklistEncryptionPublicKeys) == 0 {
|
||||
yggConfig.SessionFirewall.BlacklistEncryptionPublicKeys = []string{}
|
||||
}
|
||||
if len(yggConfig.NodeInfo) == 0 {
|
||||
yggConfig.NodeInfo = make(map[string]interface{})
|
||||
}
|
||||
}
|
||||
|
||||
func SaveConfig(yggConfig config.NodeConfig, popConfig PopuraConfig, isjson bool) string {
|
||||
// combine config structs into one and marshal it
|
||||
// FIXME hjson comments are lost
|
||||
var combo map[string]interface{}
|
||||
|
||||
ybs, _ := json.Marshal(yggConfig)
|
||||
pbs, _ := json.Marshal(popConfig)
|
||||
correctEmptyValues(&yggConfig)
|
||||
ybs, _ := json.Marshal(&yggConfig)
|
||||
pbs, _ := json.Marshal(&popConfig)
|
||||
json.Unmarshal(ybs, &combo)
|
||||
json.Unmarshal(pbs, &combo)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user