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 (
|
import (
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
|
||||||
"github.com/coreos/etcd/clientv3"
|
"github.com/coreos/etcd/clientv3"
|
||||||
|
"github.com/coreos/etcd/pkg/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GlobalFlags are flags that defined globally
|
// GlobalFlags are flags that defined globally
|
||||||
// and are inherited to all sub-commands.
|
// and are inherited to all sub-commands.
|
||||||
type GlobalFlags struct {
|
type GlobalFlags struct {
|
||||||
Endpoints string
|
Endpoints string
|
||||||
|
TLS transport.TLSInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustClient(cmd *cobra.Command) *clientv3.Client {
|
func mustClient(cmd *cobra.Command) *clientv3.Client {
|
||||||
@ -30,7 +32,25 @@ func mustClient(cmd *cobra.Command) *clientv3.Client {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
ExitWithError(ExitError, err)
|
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 {
|
if err != nil {
|
||||||
ExitWithError(ExitBadConnection, err)
|
ExitWithError(ExitBadConnection, err)
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,10 @@ var (
|
|||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().StringVar(&globalFlags.Endpoints, "endpoint", "127.0.0.1:2378", "gRPC endpoint")
|
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(
|
rootCmd.AddCommand(
|
||||||
command.NewRangeCommand(),
|
command.NewRangeCommand(),
|
||||||
command.NewPutCommand(),
|
command.NewPutCommand(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user