mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
mirror: make etcdctl make-mirror subcommand accept --dest-user and --dest-password (#11384)
This commit is contained in:
parent
e5356cca80
commit
d4d7ad3908
@ -18,6 +18,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/bgentry/speakeasy"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -37,6 +38,8 @@ var (
|
||||
mmcacert string
|
||||
mmprefix string
|
||||
mmdestprefix string
|
||||
mmuser string
|
||||
mmpassword string
|
||||
mmnodestprefix bool
|
||||
)
|
||||
|
||||
@ -56,10 +59,40 @@ func NewMakeMirrorCommand() *cobra.Command {
|
||||
c.Flags().StringVar(&mmcacert, "dest-cacert", "", "Verify certificates of TLS enabled secure servers using this CA bundle")
|
||||
// TODO: secure by default when etcd enables secure gRPC by default.
|
||||
c.Flags().BoolVar(&mminsecureTr, "dest-insecure-transport", true, "Disable transport security for client connections")
|
||||
c.Flags().StringVar(&mmuser, "dest-user", "", "Destination username[:password] for authentication (prompt if password is not supplied)")
|
||||
c.Flags().StringVar(&mmpassword, "dest-password", "", "Destination password for authentication (if this option is used, --user option shouldn't include password)")
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func authDestCfg() *authCfg {
|
||||
if mmuser == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var cfg authCfg
|
||||
|
||||
if mmpassword == "" {
|
||||
splitted := strings.SplitN(mmuser, ":", 2)
|
||||
if len(splitted) < 2 {
|
||||
var err error
|
||||
cfg.username = mmuser
|
||||
cfg.password, err = speakeasy.Ask("Destination Password: ")
|
||||
if err != nil {
|
||||
ExitWithError(ExitError, err)
|
||||
}
|
||||
} else {
|
||||
cfg.username = splitted[0]
|
||||
cfg.password = splitted[1]
|
||||
}
|
||||
} else {
|
||||
cfg.username = mmuser
|
||||
cfg.password = mmpassword
|
||||
}
|
||||
|
||||
return &cfg
|
||||
}
|
||||
|
||||
func makeMirrorCommandFunc(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
ExitWithError(ExitBadArgs, errors.New("make-mirror takes one destination argument"))
|
||||
@ -75,13 +108,15 @@ func makeMirrorCommandFunc(cmd *cobra.Command, args []string) {
|
||||
insecureTransport: mminsecureTr,
|
||||
}
|
||||
|
||||
auth := authDestCfg()
|
||||
|
||||
cc := &clientConfig{
|
||||
endpoints: []string{args[0]},
|
||||
dialTimeout: dialTimeout,
|
||||
keepAliveTime: keepAliveTime,
|
||||
keepAliveTimeout: keepAliveTimeout,
|
||||
scfg: sec,
|
||||
acfg: nil,
|
||||
acfg: auth,
|
||||
}
|
||||
dc := cc.mustClient()
|
||||
c := mustClientFromCmd(cmd)
|
||||
|
Loading…
x
Reference in New Issue
Block a user