option to hide client messages
All checks were successful
Gitea/etcdmtr/pipeline/head This commit looks good
All checks were successful
Gitea/etcdmtr/pipeline/head This commit looks good
This commit is contained in:
parent
de6e5df0d5
commit
34f4337e78
@ -17,20 +17,23 @@ import (
|
||||
var operationTimeout = 5 * time.Second
|
||||
|
||||
type EtcdMtrArgs struct {
|
||||
Version bool `long:"version" description:"Show version information"`
|
||||
ClientCert string `short:"c" long:"client-cert" description:"Client certificate pem" value-name:"FILE"`
|
||||
ClientKey string `short:"k" long:"client-key" description:"Client certificate key" value-name:"FILE"`
|
||||
ServerCA string `short:"a" long:"ca" description:"Certificate authority" value-name:"FILE"`
|
||||
Insecure bool `short:"i" long:"insecure" description:"Do not verify against CA"`
|
||||
Timeout int `short:"t" long:"timeout" description:"Operation timeout in seconds"`
|
||||
Version bool `long:"version" description:"Show version information"`
|
||||
ClientCert string `short:"c" long:"client-cert" description:"Client certificate pem" value-name:"FILE"`
|
||||
ClientKey string `short:"k" long:"client-key" description:"Client certificate key" value-name:"FILE"`
|
||||
ServerCA string `short:"a" long:"ca" description:"Certificate authority" value-name:"FILE"`
|
||||
Insecure bool `short:"i" long:"insecure" description:"Do not verify against CA"`
|
||||
Timeout int `short:"t" long:"timeout" description:"Operation timeout in seconds"`
|
||||
ExpectedMembers int `short:"m" long:"members" description:"Expect at least this many members"`
|
||||
Debug bool `long:"debug" description:"Show debug output and etcd messages"`
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
tlsConf *tls.Config
|
||||
endpoints []string
|
||||
debug bool
|
||||
}
|
||||
|
||||
func NewClient(endpoints []string, clientCertPath string, clientKeyPath string, caCertPath string) (*Client, error) {
|
||||
func NewClient(endpoints []string, clientCertPath string, clientKeyPath string, caCertPath string, debug bool) (*Client, error) {
|
||||
var tlsConf *tls.Config
|
||||
var clientCert *tls.Certificate
|
||||
var roots *x509.CertPool
|
||||
@ -69,6 +72,7 @@ func NewClient(endpoints []string, clientCertPath string, clientKeyPath string,
|
||||
return &Client{
|
||||
tlsConf: tlsConf,
|
||||
endpoints: endpoints,
|
||||
debug: debug,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -76,11 +80,15 @@ func (c *Client) GetEtcd() (*clientv3.Client, error) {
|
||||
return c.GetEtcdWithEndpoints(c.endpoints)
|
||||
}
|
||||
func (c *Client) GetEtcdWithEndpoints(endpoints []string) (*clientv3.Client, error) {
|
||||
var logger *zap.Logger
|
||||
if !c.debug {
|
||||
logger = zap.NewNop()
|
||||
}
|
||||
return clientv3.New(clientv3.Config{
|
||||
Endpoints: endpoints,
|
||||
DialTimeout: operationTimeout,
|
||||
TLS: c.tlsConf,
|
||||
Logger: zap.NewNop(),
|
||||
Logger: logger,
|
||||
})
|
||||
}
|
||||
|
||||
@ -116,7 +124,7 @@ func main() {
|
||||
operationTimeout = time.Duration(args.Timeout) * time.Second
|
||||
}
|
||||
|
||||
client, err := NewClient(positionals, args.ClientCert, args.ClientKey, args.ServerCA)
|
||||
client, err := NewClient(positionals, args.ClientCert, args.ClientKey, args.ServerCA, args.Debug)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user