mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
parent
f37c896159
commit
781bf625af
@ -17,12 +17,14 @@ package command
|
||||
import (
|
||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
|
||||
"github.com/coreos/etcd/clientv3"
|
||||
"github.com/coreos/etcd/pkg/transport"
|
||||
)
|
||||
|
||||
// GlobalFlags are flags that defined globally
|
||||
// and are inherited to all sub-commands.
|
||||
type GlobalFlags struct {
|
||||
Endpoints string
|
||||
TLS transport.TLSInfo
|
||||
}
|
||||
|
||||
func mustClient(cmd *cobra.Command) *clientv3.Client {
|
||||
@ -30,7 +32,25 @@ func mustClient(cmd *cobra.Command) *clientv3.Client {
|
||||
if err != nil {
|
||||
ExitWithError(ExitError, err)
|
||||
}
|
||||
client, err := clientv3.NewFromURL(endpoint)
|
||||
|
||||
// set tls if any one tls option set
|
||||
var cfgtls *transport.TLSInfo
|
||||
tls := transport.TLSInfo{}
|
||||
if tls.CertFile, err = cmd.Flags().GetString("cert"); err == nil {
|
||||
cfgtls = &tls
|
||||
}
|
||||
if tls.KeyFile, err = cmd.Flags().GetString("key"); err == nil {
|
||||
cfgtls = &tls
|
||||
}
|
||||
if tls.CAFile, err = cmd.Flags().GetString("cacert"); err == nil {
|
||||
cfgtls = &tls
|
||||
}
|
||||
cfg := clientv3.Config{
|
||||
Endpoints: []string{endpoint},
|
||||
TLS: cfgtls,
|
||||
}
|
||||
|
||||
client, err := clientv3.New(cfg)
|
||||
if err != nil {
|
||||
ExitWithError(ExitBadConnection, err)
|
||||
}
|
||||
|
@ -43,6 +43,10 @@ var (
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringVar(&globalFlags.Endpoints, "endpoint", "127.0.0.1:2378", "gRPC endpoint")
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.CertFile, "cert", "", "identify HTTPS client using this SSL certificate file")
|
||||
rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.KeyFile, "key", "", "identify HTTPS client using this SSL key file")
|
||||
rootCmd.PersistentFlags().StringVar(&globalFlags.TLS.CAFile, "cacert", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
|
||||
|
||||
rootCmd.AddCommand(
|
||||
command.NewRangeCommand(),
|
||||
command.NewPutCommand(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user