Skip to content

Commit

Permalink
the -scheme flag only works with srv-domain
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseyhightower committed Oct 7, 2014
1 parent b441551 commit 1b4dbb8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
26 changes: 0 additions & 26 deletions backends/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package backends

import (
"errors"
"net/url"
"strings"

"github.com/kelseyhightower/confd/backends/consul"
Expand All @@ -22,14 +21,7 @@ func New(config Config) (StoreClient, error) {
if config.Backend == "" {
config.Backend = "etcd"
}
var err error
backendNodes := config.BackendNodes
if config.Backend == "etcd" {
backendNodes, err = addScheme(config.Scheme, config.BackendNodes)
if err != nil {
return nil, err
}
}
log.Notice("Backend nodes set to " + strings.Join(backendNodes, ", "))
switch config.Backend {
case "consul":
Expand All @@ -43,21 +35,3 @@ func New(config Config) (StoreClient, error) {
}
return nil, errors.New("Invalid backend")
}

func addScheme(scheme string, nodes []string) ([]string, error) {
ns := make([]string, 0)
if scheme == "" {
scheme = "http"
}
for _, node := range nodes {
u, err := url.Parse(node)
if err != nil {
return nil, err
}
if u.Scheme == "" {
u.Scheme = scheme
}
ns = append(ns, u.String())
}
return ns, nil
}
9 changes: 5 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"errors"
"flag"
"fmt"
"io/ioutil"
"net"
"os"
Expand Down Expand Up @@ -96,7 +97,7 @@ func initConfig() error {
// Set defaults.
config = Config{
Backend: "etcd",
BackendNodes: []string{"127.0.0.1:4001"},
BackendNodes: []string{"http://127.0.0.1:4001"},
ConfDir: "/etc/confd",
Interval: 600,
Prefix: "/",
Expand Down Expand Up @@ -127,7 +128,7 @@ func initConfig() error {
// Update BackendNodes from SRV records.
if config.Backend != "env" && config.SRVDomain != "" {
log.Info("SRV domain set to " + config.SRVDomain)
srvNodes, err := getBackendNodesFromSRV(config.Backend, config.SRVDomain)
srvNodes, err := getBackendNodesFromSRV(config.Backend, config.SRVDomain, config.Scheme)
if err != nil {
return errors.New("Cannot get nodes from SRV records " + err.Error())
}
Expand Down Expand Up @@ -155,7 +156,7 @@ func initConfig() error {
return nil
}

func getBackendNodesFromSRV(backend, domain string) ([]string, error) {
func getBackendNodesFromSRV(backend, domain, scheme string) ([]string, error) {
nodes := make([]string, 0)
// Ignore the CNAME as we don't need it.
_, addrs, err := net.LookupSRV(backend, "tcp", domain)
Expand All @@ -165,7 +166,7 @@ func getBackendNodesFromSRV(backend, domain string) ([]string, error) {
for _, srv := range addrs {
host := strings.TrimRight(srv.Target, ".")
port := strconv.FormatUint(uint64(srv.Port), 10)
nodes = append(nodes, net.JoinHostPort(host, port))
nodes = append(nodes, fmt.Sprintf("%s://%s", scheme, net.JoinHostPort(host, port)))
}
return nodes, nil
}
Expand Down
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestInitConfigDefaultConfig(t *testing.T) {
log.SetQuiet(true)
want := Config{
Backend: "etcd",
BackendNodes: []string{"127.0.0.1:4001"},
BackendNodes: []string{"http://127.0.0.1:4001"},
ClientCaKeys: "",
ClientCert: "",
ClientKey: "",
Expand Down

0 comments on commit 1b4dbb8

Please sign in to comment.