diff --git a/home/upgrade.go b/home/upgrade.go index 135fd05c..2b781293 100644 --- a/home/upgrade.go +++ b/home/upgrade.go @@ -10,7 +10,7 @@ import ( yaml "gopkg.in/yaml.v2" ) -const currentSchemaVersion = 3 // used for upgrading from old configs to new config +const currentSchemaVersion = 4 // used for upgrading from old configs to new config // Performs necessary upgrade operations if needed func upgradeConfig() error { @@ -67,6 +67,11 @@ func upgradeConfigSchema(oldVersion int, diskConfig *map[string]interface{}) err if err != nil { return err } + case 3: + err := upgradeSchema3to4(diskConfig) + if err != nil { + return err + } default: err := fmt.Errorf("configuration file contains unknown schema_version, abort") log.Println(err) @@ -173,6 +178,39 @@ func upgradeSchema2to3(diskConfig *map[string]interface{}) error { return nil } +// Add use_global_blocked_services=true setting for existing "clients" array +func upgradeSchema3to4(diskConfig *map[string]interface{}) error { + log.Printf("%s(): called", _Func()) + + (*diskConfig)["schema_version"] = 4 + + clients, ok := (*diskConfig)["clients"] + if !ok { + return nil + } + + switch arr := clients.(type) { + case []interface{}: + + for i := range arr { + + switch c := arr[i].(type) { + + case map[interface{}]interface{}: + c["use_global_blocked_services"] = true + + default: + continue + } + } + + default: + return nil + } + + return nil +} + // jump three schemas at once -- this time we just do it sequentially func upgradeSchema0to3(diskConfig *map[string]interface{}) error { err := upgradeSchema0to1(diskConfig)