// New is used to create a storage client based on our configuration. func New(config Config) (StoreClient, error) { if config.Backend == "" { config.Backend = "etcd" } backendNodes := config.BackendNodes log.Info("Backend nodes set to " + strings.Join(backendNodes, ", ")) switch config.Backend { case "consul": return consul.New(config.BackendNodes, config.Scheme, config.ClientCert, config.ClientKey, config.ClientCaKeys) case "etcd": // Create the etcd client upfront and use it for the life of the process. // The etcdClient is an http.Client and designed to be reused. return etcd.NewEtcdClient(backendNodes, config.ClientCert, config.ClientKey, config.ClientCaKeys) case "zookeeper": return zookeeper.NewZookeeperClient(backendNodes) case "redis": return redis.NewRedisClient(backendNodes) case "env": return env.NewEnvClient() case "dynamodb": table := config.Table log.Info("DynamoDB table set to " + table) return dynamodb.NewDynamoDBClient(table) } return nil, errors.New("Invalid backend") }
// New is used to create a storage client based on our configuration. func New(backend string) (StoreClient, error) { if backend == "" { backend = "etcd" } switch backend { case "consul": log.Notice("Consul address set to " + config.ConsulAddr()) return consul.NewConsulClient(config.ConsulAddr()) case "etcd": // Create the etcd client upfront and use it for the life of the process. // The etcdClient is an http.Client and designed to be reused. log.Notice("etcd nodes set to " + strings.Join(config.EtcdNodes(), ", ")) return etcdutil.NewEtcdClient(config.EtcdNodes(), config.ClientCert(), config.ClientKey(), config.ClientCaKeys()) case "env": return env.NewEnvClient() } return nil, errors.New("Invalid backend") }
// New is used to create a storage client based on our configuration. func New(config Config) (StoreClient, error) { if config.Backend == "" { config.Backend = "etcd" } backendNodes := config.BackendNodes log.Info("Backend nodes set to " + strings.Join(backendNodes, ", ")) switch config.Backend { case "consul": return consul.New(config.BackendNodes, config.Scheme, config.ClientCert, config.ClientKey, config.ClientCaKeys) case "etcd": // Create the etcd client upfront and use it for the life of the process. // The etcdClient is an http.Client and designed to be reused. return etcd.NewEtcdClient(backendNodes, config.ClientCert, config.ClientKey, config.ClientCaKeys, config.BasicAuth, config.Username, config.Password) case "zookeeper": return zookeeper.NewZookeeperClient(backendNodes) case "rancher": return rancher.NewRancherClient(backendNodes) case "redis": return redis.NewRedisClient(backendNodes, config.ClientKey) case "env": return env.NewEnvClient() case "vault": vaultConfig := map[string]string{ "app-id": config.AppID, "user-id": config.UserID, "username": config.Username, "password": config.Password, "token": config.AuthToken, "cert": config.ClientCert, "key": config.ClientKey, "caCert": config.ClientCaKeys, } return vault.New(backendNodes[0], config.AuthType, vaultConfig) case "dynamodb": table := config.Table log.Info("DynamoDB table set to " + table) return dynamodb.NewDynamoDBClient(table) case "stackengine": return stackengine.NewStackEngineClient(backendNodes, config.Scheme, config.ClientCert, config.ClientKey, config.ClientCaKeys, config.AuthToken) } return nil, errors.New("Invalid backend") }
// New is used to create a storage client based on our configuration. func New(config Config) (StoreClient, error) { if config.Backend == "" { config.Backend = "etcd" } backendNodes := config.BackendNodes log.Info("Backend nodes set to " + strings.Join(backendNodes, ", ")) switch config.Backend { case "consul": return consul.New(config.BackendNodes, config.Scheme, config.ClientCert, config.ClientKey, config.ClientCaKeys) case "etcd": // Create the etcd client upfront and use it for the life of the process. // The etcdClient is an http.Client and designed to be reused. return etcd.NewEtcdClient(backendNodes, config.ClientCert, config.ClientKey, config.ClientCaKeys) case "zookeeper": return zookeeper.NewZookeeperClient(backendNodes) case "redis": return redis.NewRedisClient(backendNodes) case "env": return env.NewEnvClient() case "dynamodb": table := config.Table log.Info("DynamoDB table set to " + table) return dynamodb.NewDynamoDBClient(table) case "stackengine": return stackengine.NewStackEngineClient(backendNodes, config.Scheme, config.ClientCert, config.ClientKey, config.ClientCaKeys, config.AuthToken) case "autoscaling": asg := config.Asg region := config.AWSRegion log.Info("Auto Scaling Group set to " + asg) log.Debug("AWS Region set to " + region) return autoscaling.NewAsgClient(asg, ®ion) } return nil, errors.New("Invalid backend") }
func TestProcessTemplateResources(t *testing.T) { log.SetLevel("warn") // Setup temporary conf, config, and template directories. tempConfDir, err := createTempDirs() if err != nil { t.Errorf("Failed to create temp dirs: %s", err.Error()) } defer os.RemoveAll(tempConfDir) // Create the src template. srcTemplateFile := filepath.Join(tempConfDir, "templates", "foo.tmpl") err = ioutil.WriteFile(srcTemplateFile, []byte(`foo = {{getv "/foo"}}`), 0644) if err != nil { t.Error(err.Error()) } // Create the dest. destFile, err := ioutil.TempFile("", "") if err != nil { t.Errorf("Failed to create destFile: %s", err.Error()) } defer os.Remove(destFile.Name()) // Create the template resource configuration file. templateResourcePath := filepath.Join(tempConfDir, "conf.d", "foo.toml") templateResourceFile, err := os.Create(templateResourcePath) if err != nil { t.Errorf(err.Error()) } tmpl, err := template.New("templateResourceConfig").Parse(templateResourceConfigTmpl) if err != nil { t.Errorf("Unable to parse template resource template: %s", err.Error()) } data := make(map[string]string) data["src"] = "foo.tmpl" data["dest"] = destFile.Name() err = tmpl.Execute(templateResourceFile, data) if err != nil { t.Errorf(err.Error()) } os.Setenv("FOO", "bar") storeClient, err := env.NewEnvClient() if err != nil { t.Errorf(err.Error()) } c := Config{ ConfDir: tempConfDir, ConfigDir: filepath.Join(tempConfDir, "conf.d"), StoreClient: storeClient, TemplateDir: filepath.Join(tempConfDir, "templates"), } // Process the test template resource. err = Process(c) if err != nil { t.Error(err.Error()) } // Verify the results. expected := "foo = bar" results, err := ioutil.ReadFile(destFile.Name()) if err != nil { t.Error(err.Error()) } if string(results) != expected { t.Errorf("Expected contents of dest == '%s', got %s", expected, string(results)) } }