Skip to content
Snippets Groups Projects
Commit 6c595930 authored by ale's avatar ale
Browse files

pass etcd server URLs as-is to the etcd client

parent a6bbeb41
No related branches found
No related tags found
No related merge requests found
......@@ -4,14 +4,13 @@ import (
"flag"
"io/ioutil"
"log"
"net"
"strings"
"git.autistici.org/ale/autoradio/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd"
)
var (
etcdMachines = flag.String("etcd-servers", "localhost:2379", "Etcd servers (comma-separated list)")
etcdMachines = flag.String("etcd-servers", "http://127.0.0.1:2379", "Etcd server URLs (comma-separated list)")
etcdCertFile = flag.String("etcd-cert", "", "SSL certificate for etcd client")
etcdKeyFile = flag.String("etcd-key", "", "SSL private key for etcd client")
etcdCaFile = flag.String("etcd-ca", "", "SSL CA certificate for etcd client")
......@@ -25,45 +24,19 @@ func mustLoadFile(path string) string {
return string(data)
}
// Resolve a list of etcd host:port specs, returning URLs.
func resolveAll(input []string, proto string) []string {
var result []string
for _, hostport := range input {
host, port, err := net.SplitHostPort(hostport)
if err != nil {
log.Fatalf("Error parsing etcd server spec '%s': %s", hostport, err)
}
addrs, err := net.LookupHost(host)
if err != nil {
log.Fatalf("Error resolving etcd server spec '%s': %s", hostport, err)
}
for _, a := range addrs {
url := proto + "://" + net.JoinHostPort(a, port)
result = append(result, url)
}
}
return result
}
// NewEtcdClient creates a new etcd client. It uses command-line flags
// to find servers and connection parameters. If the 'strongReads'
// argument is true, read requests will also be sent to the etcd
// master and should be able to see the effect of previous writes.
func NewEtcdClient(strongReads bool) EtcdClient {
proto := "http"
if *etcdCertFile != "" && *etcdKeyFile != "" {
proto = "https"
}
// Resolve etcd servers.
machines := resolveAll(strings.Split(*etcdMachines, ","), proto)
if len(machines) == 0 {
machines := strings.Split(*etcdMachines, ",")
if len(machines) < 1 {
log.Fatal("No etcd servers specified!")
}
// Create the etcd client.
var c *etcd.Client
if proto == "https" {
if *etcdCertFile != "" && *etcdKeyFile != "" {
var err error
c, err = etcd.NewTLSClient(machines,
mustLoadFile(*etcdCertFile),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment