Skip to content

Commit d756687

Browse files
committed
Add augerctl get
Signed-off-by: Shiming Zhang <[email protected]>
1 parent 52beb8e commit d756687

12 files changed

+918
-0
lines changed

cmd/augerctl/main.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"fmt"
21+
"os"
22+
23+
"github.com/etcd-io/auger/pkg/augerctl"
24+
)
25+
26+
func main() {
27+
if err := augerctl.NewCtlCommand().Execute(); err != nil {
28+
fmt.Println(err)
29+
os.Exit(1)
30+
}
31+
}

go.mod

+11
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ require (
77
github.com/spf13/cobra v1.8.1
88
go.etcd.io/bbolt v1.3.10
99
go.etcd.io/etcd/api/v3 v3.5.15
10+
go.etcd.io/etcd/client/pkg/v3 v3.5.15
11+
go.etcd.io/etcd/client/v3 v3.5.15
1012
gopkg.in/yaml.v2 v2.4.0
1113
k8s.io/api v0.30.3
1214
k8s.io/apimachinery v0.30.3
1315
k8s.io/client-go v0.30.3
1416
)
1517

1618
require (
19+
github.com/coreos/go-semver v0.3.0 // indirect
20+
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
1721
github.com/go-logr/logr v1.4.2 // indirect
1822
github.com/gogo/protobuf v1.3.2 // indirect
1923
github.com/golang/protobuf v1.5.4 // indirect
@@ -24,9 +28,16 @@ require (
2428
github.com/modern-go/reflect2 v1.0.2 // indirect
2529
github.com/spf13/pflag v1.0.5 // indirect
2630
github.com/stretchr/testify v1.9.0 // indirect
31+
go.uber.org/atomic v1.7.0 // indirect
32+
go.uber.org/multierr v1.6.0 // indirect
33+
go.uber.org/zap v1.17.0 // indirect
2734
golang.org/x/net v0.27.0 // indirect
2835
golang.org/x/sys v0.22.0 // indirect
2936
golang.org/x/text v0.16.0 // indirect
37+
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
38+
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
39+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
40+
google.golang.org/grpc v1.59.0 // indirect
3041
google.golang.org/protobuf v1.34.2 // indirect
3142
gopkg.in/inf.v0 v0.9.1 // indirect
3243
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

+29
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
2+
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
3+
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
4+
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
15
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
26
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
37
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
48
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
59
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
610
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
11+
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
712
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
813
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
914
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
@@ -31,6 +36,9 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
3136
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
3237
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
3338
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
39+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
40+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
41+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3442
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3543
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3644
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
@@ -42,6 +50,7 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
4250
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
4351
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4452
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
53+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4554
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
4655
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4756
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -50,6 +59,16 @@ go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0=
5059
go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ=
5160
go.etcd.io/etcd/api/v3 v3.5.15 h1:3KpLJir1ZEBrYuV2v+Twaa/e2MdDCEZ/70H+lzEiwsk=
5261
go.etcd.io/etcd/api/v3 v3.5.15/go.mod h1:N9EhGzXq58WuMllgH9ZvnEr7SI9pS0k0+DHZezGp7jM=
62+
go.etcd.io/etcd/client/pkg/v3 v3.5.15 h1:fo0HpWz/KlHGMCC+YejpiCmyWDEuIpnTDzpJLB5fWlA=
63+
go.etcd.io/etcd/client/pkg/v3 v3.5.15/go.mod h1:mXDI4NAOwEiszrHCb0aqfAYNCrZP4e9hRca3d1YK8EU=
64+
go.etcd.io/etcd/client/v3 v3.5.15 h1:23M0eY4Fd/inNv1ZfU3AxrbbOdW79r9V9Rl62Nm6ip4=
65+
go.etcd.io/etcd/client/v3 v3.5.15/go.mod h1:CLSJxrYjvLtHsrPKsy7LmZEE+DK2ktfd2bN4RhBMwlU=
66+
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
67+
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
68+
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
69+
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
70+
go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U=
71+
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
5372
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
5473
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
5574
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -83,6 +102,14 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
83102
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
84103
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
85104
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
105+
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d h1:VBu5YqKPv6XiJ199exd8Br+Aetz+o08F+PLMnwJQHAY=
106+
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d/go.mod h1:yZTlhN0tQnXo3h00fuXNCxJdLdIdnVFVBaRJ5LWBbw4=
107+
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q=
108+
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
109+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4=
110+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
111+
google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
112+
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
86113
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
87114
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
88115
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -93,6 +120,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
93120
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
94121
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
95122
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
123+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
124+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
96125
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
97126
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
98127
k8s.io/api v0.30.3 h1:ImHwK9DCsPA9uoU3rVh4QHAHHK5dTSv1nxJUapx8hoQ=

pkg/augerctl/ctl.go

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package augerctl is A simple command line client for directly access data objects stored in etcd by Kubernetes.
18+
package augerctl
19+
20+
import (
21+
"github.com/spf13/cobra"
22+
23+
"go.etcd.io/etcd/client/pkg/v3/transport"
24+
)
25+
26+
type flagpole struct {
27+
Endpoints []string
28+
29+
InsecureSkipVerify bool
30+
InsecureDiscovery bool
31+
TLS transport.TLSInfo
32+
33+
User string
34+
Password string
35+
}
36+
37+
// NewCtlCommand returns a new cobra.Command for use ctl
38+
func NewCtlCommand() *cobra.Command {
39+
flags := &flagpole{}
40+
41+
cmd := &cobra.Command{
42+
Use: "augerctl",
43+
Short: "A simple command line client for directly access data objects stored in etcd by Kubernetes.",
44+
}
45+
cmd.PersistentFlags().StringSliceVar(&flags.Endpoints, "endpoints", []string{"127.0.0.1:2379"}, "gRPC endpoints")
46+
47+
cmd.PersistentFlags().BoolVar(&flags.InsecureDiscovery, "insecure-discovery", true, "accept insecure SRV records describing cluster endpoints")
48+
cmd.PersistentFlags().BoolVar(&flags.InsecureSkipVerify, "insecure-skip-tls-verify", false, "skip server certificate verification")
49+
cmd.PersistentFlags().StringVar(&flags.TLS.CertFile, "cert", "", "identify secure client using this TLS certificate file")
50+
cmd.PersistentFlags().StringVar(&flags.TLS.KeyFile, "key", "", "identify secure client using this TLS key file")
51+
cmd.PersistentFlags().StringVar(&flags.TLS.TrustedCAFile, "cacert", "", "verify certificates of TLS-enabled secure servers using this CA bundle")
52+
cmd.PersistentFlags().StringVar(&flags.User, "user", "", "username for authentication")
53+
cmd.PersistentFlags().StringVar(&flags.Password, "password", "", "password for authentication")
54+
55+
cmd.AddCommand(
56+
newCtlGetCommand(flags),
57+
)
58+
return cmd
59+
}

pkg/augerctl/get_command.go

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package augerctl
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"os"
23+
24+
"github.com/etcd-io/auger/pkg/client"
25+
"github.com/spf13/cobra"
26+
"k8s.io/apimachinery/pkg/runtime/schema"
27+
)
28+
29+
type getFlagpole struct {
30+
Namespace string
31+
Output string
32+
ChunkSize int64
33+
Prefix string
34+
}
35+
36+
func newCtlGetCommand(f *flagpole) *cobra.Command {
37+
flags := &getFlagpole{}
38+
39+
cmd := &cobra.Command{
40+
Args: cobra.RangeArgs(0, 2),
41+
Use: "get [resource] [name]",
42+
Short: "Gets the resource of Kubernetes in etcd",
43+
RunE: func(cmd *cobra.Command, args []string) error {
44+
etcdclient, err := clientFromCmd(f)
45+
if err != nil {
46+
return err
47+
}
48+
err = getCommand(cmd.Context(), etcdclient, flags, args)
49+
50+
if err != nil {
51+
return fmt.Errorf("%v: %w", args, err)
52+
}
53+
return nil
54+
},
55+
}
56+
57+
cmd.Flags().StringVarP(&flags.Output, "output", "o", "yaml", "output format. One of: (yaml).")
58+
cmd.Flags().StringVarP(&flags.Namespace, "namespace", "n", "", "namespace of resource")
59+
cmd.Flags().Int64Var(&flags.ChunkSize, "chunk-size", 500, "chunk size of the list pager")
60+
cmd.Flags().StringVar(&flags.Prefix, "prefix", "/registry", "prefix to prepend to the resource")
61+
62+
return cmd
63+
}
64+
65+
func getCommand(ctx context.Context, etcdclient client.Client, flags *getFlagpole, args []string) error {
66+
var targetGr schema.GroupResource
67+
var targetName string
68+
var targetNamespace string
69+
if len(args) != 0 {
70+
// TODO: Support get information from CRD and scheme.Codecs
71+
// Support short name
72+
// Check for namespaced
73+
74+
gr := schema.ParseGroupResource(args[0])
75+
if gr.Empty() {
76+
return fmt.Errorf("invalid resource %q", args[0])
77+
}
78+
targetGr = gr
79+
targetNamespace = flags.Namespace
80+
if len(args) >= 2 {
81+
targetName = args[1]
82+
}
83+
}
84+
85+
printer := NewPrinter(os.Stdout, flags.Output)
86+
if printer == nil {
87+
return fmt.Errorf("invalid output format: %q", flags.Output)
88+
}
89+
90+
opOpts := []client.OpOption{
91+
client.WithName(targetName, targetNamespace),
92+
client.WithGR(targetGr),
93+
client.WithPageLimit(flags.ChunkSize),
94+
client.WithResponse(printer.Print),
95+
}
96+
97+
// TODO: Support watch
98+
99+
_, err := etcdclient.Get(ctx, flags.Prefix,
100+
opOpts...,
101+
)
102+
if err != nil {
103+
return err
104+
}
105+
106+
return nil
107+
}

pkg/augerctl/global.go

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package augerctl
18+
19+
import (
20+
"crypto/tls"
21+
22+
"github.com/etcd-io/auger/pkg/client"
23+
24+
clientv3 "go.etcd.io/etcd/client/v3"
25+
)
26+
27+
func clientFromCmd(f *flagpole) (client.Client, error) {
28+
cfg, err := clientConfigFromCmd(f)
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
cli, err := clientv3.New(cfg)
34+
if err != nil {
35+
return nil, err
36+
}
37+
38+
return client.NewClient(cli), nil
39+
}
40+
41+
func clientConfigFromCmd(f *flagpole) (clientv3.Config, error) {
42+
cfg := clientv3.Config{
43+
Endpoints: f.Endpoints,
44+
}
45+
46+
if !f.TLS.Empty() {
47+
clientTLS, err := f.TLS.ClientConfig()
48+
if err != nil {
49+
return clientv3.Config{}, err
50+
}
51+
cfg.TLS = clientTLS
52+
}
53+
54+
// if key/cert is not given but user wants secure connection, we
55+
// should still setup an empty tls configuration for gRPC to setup
56+
// secure connection.
57+
if cfg.TLS == nil && !f.InsecureDiscovery {
58+
cfg.TLS = &tls.Config{}
59+
}
60+
61+
// If the user wants to skip TLS verification then we should set
62+
// the InsecureSkipVerify flag in tls configuration.
63+
if cfg.TLS != nil && f.InsecureSkipVerify {
64+
cfg.TLS.InsecureSkipVerify = true
65+
}
66+
67+
cfg.Username = f.User
68+
cfg.Password = f.Password
69+
70+
return cfg, nil
71+
}

0 commit comments

Comments
 (0)