etcdctl: add --ca-file, --cert-file, --key-file flags
This commit is contained in:
@ -47,7 +47,13 @@ func rawhandle(c *cli.Context, fn handlerFunc) (*etcd.Response, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tr, err := getTransport(c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
client := etcd.NewClient(endpoints)
|
client := etcd.NewClient(endpoints)
|
||||||
|
client.SetTransport(tr)
|
||||||
|
|
||||||
if c.GlobalBool("debug") {
|
if c.GlobalBool("debug") {
|
||||||
go dumpCURL(client)
|
go dumpCURL(client)
|
||||||
|
@ -18,7 +18,6 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -58,7 +57,13 @@ func mustNewMembersAPI(c *cli.Context) client.MembersAPI {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
hc, err := client.NewHTTPClient(&http.Transport{}, eps)
|
tr, err := getTransport(c)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
hc, err := client.NewHTTPClient(tr, eps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err.Error())
|
fmt.Fprintln(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -20,11 +20,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
|
||||||
|
"github.com/coreos/etcd/pkg/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -54,19 +56,6 @@ func argOrStdin(args []string, stdin io.Reader, i int) (string, error) {
|
|||||||
return string(bytes), nil
|
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 {
|
func getPeersFlagValue(c *cli.Context) []string {
|
||||||
peerstr := c.GlobalString("peers")
|
peerstr := c.GlobalString("peers")
|
||||||
|
|
||||||
@ -86,12 +75,27 @@ func getPeersFlagValue(c *cli.Context) []string {
|
|||||||
|
|
||||||
func getEndpoints(c *cli.Context) ([]string, error) {
|
func getEndpoints(c *cli.Context) ([]string, error) {
|
||||||
eps := getPeersFlagValue(c)
|
eps := getPeersFlagValue(c)
|
||||||
var err error
|
|
||||||
for i, ep := range eps {
|
for i, ep := range eps {
|
||||||
eps[i], err = maybeAddScheme(ep)
|
u, err := url.Parse(ep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if u.Scheme == "" {
|
||||||
|
u.Scheme = "http"
|
||||||
|
}
|
||||||
|
|
||||||
|
eps[i] = u.String()
|
||||||
}
|
}
|
||||||
return eps, nil
|
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)
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -35,6 +35,9 @@ func main() {
|
|||||||
cli.BoolFlag{Name: "no-sync", Usage: "don't synchronize cluster information before sending request"},
|
cli.BoolFlag{Name: "no-sync", Usage: "don't synchronize cluster information before sending request"},
|
||||||
cli.StringFlag{Name: "output, o", Value: "simple", Usage: "output response in the given format (`simple` or `json`)"},
|
cli.StringFlag{Name: "output, o", Value: "simple", Usage: "output response in the given format (`simple` or `json`)"},
|
||||||
cli.StringFlag{Name: "peers, C", Value: "", Usage: "a comma-delimited list of machine addresses in the cluster (default: \"127.0.0.1:4001\")"},
|
cli.StringFlag{Name: "peers, C", Value: "", Usage: "a comma-delimited list of machine addresses in the cluster (default: \"127.0.0.1:4001\")"},
|
||||||
|
cli.StringFlag{Name: "cert-file", Value: "", Usage: "identify HTTPS client using this SSL certificate file"},
|
||||||
|
cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"},
|
||||||
|
cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"},
|
||||||
}
|
}
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
command.NewMakeCommand(),
|
command.NewMakeCommand(),
|
||||||
|
Reference in New Issue
Block a user