func printConfig(title string, c types.Config, t *testing.T) { for _, k := range c.AllKeys() { if title == "" { t.Logf("%s=%v", k, c.Get(k)) } else { t.Logf("%s - %s=%v", title, k, c.Get(k)) } } }
func assertConfigsEqual(c1 types.Config, c2 types.Config, t *testing.T) bool { printConfig("c1", c1, t) t.Log("") printConfig("c2", c2, t) t.Log("") c1Keys := c1.AllKeys() c2Keys := c2.AllKeys() for _, k := range c1Keys { c1v := c1.Get(k) c2v := c2.Get(k) if !reflect.DeepEqual(c1v, c2v) { t.Logf("%s != in both configs; "+ "c1v:type=%[2]T,val=%[2]v; "+ "c2v:type=%[3]T,val=%[3]v", k, c1v, c2v) return false } } for _, k := range c2Keys { c1v := c1.Get(k) c2v := c2.Get(k) if !reflect.DeepEqual(c1v, c2v) { t.Logf("%s != in both configs; "+ "c1v:type=%[2]T,val=%[2]v; "+ "c2v:type=%[3]T,val=%[3]v", k, c1v, c2v) return false } } return true }
// BackCompat ensures keys can be used from old configurations. func BackCompat(config gofig.Config) { ec2Checks := [][]string{ {ConfigEBSAccessKey, ConfigEC2AccessKey}, {ConfigEBSSecretKey, ConfigEC2SecretKey}, {ConfigEBSRegion, ConfigEC2Region}, {ConfigEBSEndpoint, ConfigEC2Endpoint}, {ConfigEBSMaxRetries, ConfigEC2MaxRetries}, {ConfigEBSTag, ConfigEC2Tag}, {ConfigEBSRexrayTag, ConfigEC2RexrayTag}, {ConfigEBSKmsKeyID, ConfigEC2KmsKeyID}, } for _, check := range ec2Checks { if !config.IsSet(check[0]) && config.IsSet(check[1]) { log.Debug(config.Get(check[1])) config.Set(check[0], config.Get(check[1])) } } awsChecks := [][]string{ {ConfigEBSAccessKey, ConfigAWSAccessKey}, {ConfigEBSSecretKey, ConfigAWSSecretKey}, {ConfigEBSRegion, ConfigAWSRegion}, {ConfigEBSEndpoint, ConfigAWSEndpoint}, {ConfigEBSMaxRetries, ConfigAWSMaxRetries}, {ConfigEBSTag, ConfigAWSTag}, {ConfigEBSRexrayTag, ConfigAWSRexrayTag}, {ConfigEBSKmsKeyID, ConfigAWSKmsKeyID}, } for _, check := range awsChecks { if !config.IsSet(check[0]) && config.IsSet(check[1]) { log.Debug(config.Get(check[1])) config.Set(check[0], config.Get(check[1])) } } }
func getConfiguredModules( ctx apitypes.Context, c gofig.Config) ([]*Config, error) { mods := c.Get("rexray.modules") modMap, ok := mods.(map[string]interface{}) if !ok { return nil, goof.New("invalid format rexray.modules") } ctx.WithField("count", len(modMap)).Debug("got modules map") modConfigs := []*Config{} for name := range modMap { name = strings.ToLower(name) ctx.WithField("name", name).Debug("processing module config") sc := c.Scope(fmt.Sprintf("rexray.modules.%s", name)) if disabled := sc.GetBool("disabled"); disabled { ctx.WithField("name", name).Debug("ignoring disabled module config") continue } mc := &Config{ Name: name, Type: strings.ToLower(sc.GetString("type")), Description: sc.GetString("desc"), Address: sc.GetString("host"), Config: sc, } ctx.WithFields(log.Fields{ "name": mc.Name, "type": mc.Type, "desc": mc.Description, "addr": mc.Address, }).Info("created new mod config") modConfigs = append(modConfigs, mc) } return modConfigs, nil }
// BackCompat ensures keys can be used from old configurations. func BackCompat(config gofig.Config) { checks := [][]string{ {ConfigIgVolOpsMountPreempt, ConfigOldIntegrationVolMountPreempt}, {ConfigIgVolOpsCreateDisable, ConfigOldIntegrationVolCreateDisable}, {ConfigIgVolOpsRemoveDisable, ConfigOldIntegrationVolRemoveDisable}, {ConfigIgVolOpsUnmountIgnoreUsed, ConfigOldIntegrationVolUnmountIgnoreUsed}, {ConfigIgVolOpsPathCacheEnabled, ConfigOldIntegrationVolPathCache}, {ConfigIgVolOpsCreateDefaultFsType, ConfigOldDockerFsType}, {ConfigIgVolOpsCreateDefaultType, ConfigOldDockerVolumeType}, {ConfigIgVolOpsCreateDefaultIOPS, ConfigOldDockerIOPS}, {ConfigIgVolOpsCreateDefaultSize, ConfigOldDockerSize}, {ConfigIgVolOpsCreateDefaultAZ, ConfigOldDockerAvailabilityZone}, {ConfigIgVolOpsMountPath, ConfigOldDockerMountDirPath}, {ConfigIgVolOpsMountRootPath, ConfigOldDockerLinuxVolumeRootPath}, } for _, check := range checks { if !config.IsSet(check[0]) && config.IsSet(check[1]) { log.Debug(config.Get(check[1])) config.Set(check[0], config.Get(check[1])) } } }