Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Support NonTLS option for testing purpose only. #67

Merged
merged 5 commits into from
Feb 3, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
serverCert = flag.String("server_crt", "", "TLS server certificate")
serverKey = flag.String("server_key", "", "TLS server private key")
insecure = flag.Bool("insecure", false, "Skip providing TLS cert and key, for testing only!")
noTLS = flag.Bool("noTLS", false, "disable TLS, for testing only!")
allowNoClientCert = flag.Bool("allow_no_client_auth", false, "When set, telemetry server will request but not require a client certificate.")
)

Expand All @@ -32,10 +33,17 @@ func main() {
log.Errorf("port must be > 0.")
return
}
var certificate tls.Certificate
var err error

cfg := &gnmi.Config{}
cfg.Port = int64(*port)
var opts []grpc.ServerOption

if !*noTLS {
var certificate tls.Certificate
var err error

if *insecure {
pra-moh marked this conversation as resolved.
Show resolved Hide resolved

certificate, err = testcert.NewCert()
if err != nil {
log.Exitf("could not load server key pair: %s", err)
Expand Down Expand Up @@ -91,9 +99,9 @@ func main() {
tlsCfg.ClientCAs = certPool
}

opts := []grpc.ServerOption{grpc.Creds(credentials.NewTLS(tlsCfg))}
cfg := &gnmi.Config{}
cfg.Port = int64(*port)
opts = []grpc.ServerOption{grpc.Creds(credentials.NewTLS(tlsCfg))}
}

s, err := gnmi.NewServer(cfg, opts)
if err != nil {
log.Errorf("Failed to create gNMI server: %v", err)
Expand Down