etcdctl: add --ca-file, --cert-file, --key-file flags

This commit is contained in:
Brian Waldon
2014-11-06 12:16:07 -08:00
parent 902f06c5c4
commit 2d942e970b
4 changed files with 35 additions and 17 deletions

View File

@ -20,11 +20,13 @@ import (
"errors"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
"github.com/coreos/etcd/pkg/transport"
)
var (
@ -54,19 +56,6 @@ func argOrStdin(args []string, stdin io.Reader, i int) (string, error) {
return string(bytes), nil
}
func maybeAddScheme(maybeAddr string) (string, error) {
u, err := url.Parse(maybeAddr)
if err != nil {
return "", err
}
if u.Scheme == "" {
u.Scheme = "http"
}
return u.String(), nil
}
func getPeersFlagValue(c *cli.Context) []string {
peerstr := c.GlobalString("peers")
@ -86,12 +75,27 @@ func getPeersFlagValue(c *cli.Context) []string {
func getEndpoints(c *cli.Context) ([]string, error) {
eps := getPeersFlagValue(c)
var err error
for i, ep := range eps {
eps[i], err = maybeAddScheme(ep)
u, err := url.Parse(ep)
if err != nil {
return nil, err
}
if u.Scheme == "" {
u.Scheme = "http"
}
eps[i] = u.String()
}
return eps, nil
}
func getTransport(c *cli.Context) (*http.Transport, error) {
tls := transport.TLSInfo{
CAFile: c.GlobalString("ca-file"),
CertFile: c.GlobalString("cert-file"),
KeyFile: c.GlobalString("key-file"),
}
return transport.NewTransport(tls)
}