|
@@ -19,8 +19,10 @@ import (
|
|
|
"errors"
|
|
"errors"
|
|
|
"io"
|
|
"io"
|
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
|
|
|
+ "strings"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
|
|
+ "github.com/bgentry/speakeasy"
|
|
|
"github.com/coreos/etcd/clientv3"
|
|
"github.com/coreos/etcd/clientv3"
|
|
|
"github.com/coreos/etcd/pkg/flags"
|
|
"github.com/coreos/etcd/pkg/flags"
|
|
|
"github.com/coreos/etcd/pkg/transport"
|
|
"github.com/coreos/etcd/pkg/transport"
|
|
@@ -40,6 +42,8 @@ type GlobalFlags struct {
|
|
|
|
|
|
|
|
OutputFormat string
|
|
OutputFormat string
|
|
|
IsHex bool
|
|
IsHex bool
|
|
|
|
|
+
|
|
|
|
|
+ User string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type secureCfg struct {
|
|
type secureCfg struct {
|
|
@@ -51,6 +55,11 @@ type secureCfg struct {
|
|
|
insecureSkipVerify bool
|
|
insecureSkipVerify bool
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+type authCfg struct {
|
|
|
|
|
+ username string
|
|
|
|
|
+ password string
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
var display printer = &simplePrinter{}
|
|
var display printer = &simplePrinter{}
|
|
|
|
|
|
|
|
func initDisplayFromCmd(cmd *cobra.Command) {
|
|
func initDisplayFromCmd(cmd *cobra.Command) {
|
|
@@ -76,14 +85,15 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
|
|
|
}
|
|
}
|
|
|
dialTimeout := dialTimeoutFromCmd(cmd)
|
|
dialTimeout := dialTimeoutFromCmd(cmd)
|
|
|
sec := secureCfgFromCmd(cmd)
|
|
sec := secureCfgFromCmd(cmd)
|
|
|
|
|
+ auth := authCfgFromCmd(cmd)
|
|
|
|
|
|
|
|
initDisplayFromCmd(cmd)
|
|
initDisplayFromCmd(cmd)
|
|
|
|
|
|
|
|
- return mustClient(endpoints, dialTimeout, sec)
|
|
|
|
|
|
|
+ return mustClient(endpoints, dialTimeout, sec, auth)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func mustClient(endpoints []string, dialTimeout time.Duration, scfg *secureCfg) *clientv3.Client {
|
|
|
|
|
- cfg, err := newClientCfg(endpoints, dialTimeout, scfg)
|
|
|
|
|
|
|
+func mustClient(endpoints []string, dialTimeout time.Duration, scfg *secureCfg, acfg *authCfg) *clientv3.Client {
|
|
|
|
|
+ cfg, err := newClientCfg(endpoints, dialTimeout, scfg, acfg)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
ExitWithError(ExitBadArgs, err)
|
|
ExitWithError(ExitBadArgs, err)
|
|
|
}
|
|
}
|
|
@@ -96,7 +106,7 @@ func mustClient(endpoints []string, dialTimeout time.Duration, scfg *secureCfg)
|
|
|
return client
|
|
return client
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func newClientCfg(endpoints []string, dialTimeout time.Duration, scfg *secureCfg) (*clientv3.Config, error) {
|
|
|
|
|
|
|
+func newClientCfg(endpoints []string, dialTimeout time.Duration, scfg *secureCfg, acfg *authCfg) (*clientv3.Config, error) {
|
|
|
// set tls if any one tls option set
|
|
// set tls if any one tls option set
|
|
|
var cfgtls *transport.TLSInfo
|
|
var cfgtls *transport.TLSInfo
|
|
|
tlsinfo := transport.TLSInfo{}
|
|
tlsinfo := transport.TLSInfo{}
|
|
@@ -138,6 +148,12 @@ func newClientCfg(endpoints []string, dialTimeout time.Duration, scfg *secureCfg
|
|
|
if scfg.insecureSkipVerify && cfg.TLS != nil {
|
|
if scfg.insecureSkipVerify && cfg.TLS != nil {
|
|
|
cfg.TLS.InsecureSkipVerify = true
|
|
cfg.TLS.InsecureSkipVerify = true
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if acfg != nil {
|
|
|
|
|
+ cfg.Username = acfg.username
|
|
|
|
|
+ cfg.Password = acfg.password
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return cfg, nil
|
|
return cfg, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -213,3 +229,30 @@ func keyAndCertFromCmd(cmd *cobra.Command) (cert, key, cacert string) {
|
|
|
|
|
|
|
|
return cert, key, cacert
|
|
return cert, key, cacert
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func authCfgFromCmd(cmd *cobra.Command) *authCfg {
|
|
|
|
|
+ userFlag, err := cmd.Flags().GetString("user")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ ExitWithError(ExitBadArgs, err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if userFlag == "" {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var cfg authCfg
|
|
|
|
|
+
|
|
|
|
|
+ splitted := strings.SplitN(userFlag, ":", 2)
|
|
|
|
|
+ if len(splitted) == 0 {
|
|
|
|
|
+ cfg.username = userFlag
|
|
|
|
|
+ cfg.password, err = speakeasy.Ask("Password: ")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ ExitWithError(ExitError, err)
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ cfg.username = splitted[0]
|
|
|
|
|
+ cfg.password = splitted[1]
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return &cfg
|
|
|
|
|
+}
|