certmanager updates
This commit is contained in:
51
pkg/client/client.go
Normal file
51
pkg/client/client.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"certmanager/pkg/cmctl"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultWrpcPort int = 20311
|
||||
DefaultGrpcPort int = 20312
|
||||
)
|
||||
|
||||
type Access struct {
|
||||
Hostname string
|
||||
Port int
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
func NewClient(access *Access) (cmctl.ControlClient, error) {
|
||||
var err error
|
||||
var cli cmctl.ControlClient
|
||||
|
||||
tlsConfig := &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
const dialTimeout time.Duration = 1 * time.Second
|
||||
const idleTimeout time.Duration = 5 * time.Second
|
||||
|
||||
authCred := NewAuthCredential(access.Username, access.Password)
|
||||
dialOpts := []grpc.DialOption{
|
||||
grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)),
|
||||
grpc.WithPerRPCCredentials(authCred),
|
||||
grpc.WithBlock(),
|
||||
grpc.WithIdleTimeout(idleTimeout),
|
||||
}
|
||||
address := fmt.Sprintf("%s:%d", access.Hostname, access.Port)
|
||||
ctx, _ := context.WithTimeout(context.Background(), dialTimeout)
|
||||
conn, err := grpc.DialContext(ctx, address, dialOpts...)
|
||||
if err != nil {
|
||||
return cli, fmt.Errorf("Dial error: %v", err)
|
||||
}
|
||||
cli = cmctl.NewControlClient(conn)
|
||||
return cli, err
|
||||
}
|
||||
Reference in New Issue
Block a user