certmanager updates
This commit is contained in:
@@ -6,27 +6,15 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
cmapi "certmanager/pkg/cmctl"
|
||||
"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
|
||||
}
|
||||
|
||||
type Control struct {
|
||||
conn *grpc.ClientConn
|
||||
client cmapi.ControlClient
|
||||
client cmctl.ControlClient
|
||||
}
|
||||
|
||||
func NewControl(access *Access) (*Control, error) {
|
||||
@@ -54,7 +42,7 @@ func NewControl(access *Access) (*Control, error) {
|
||||
return cont, fmt.Errorf("Dial error: %v", err)
|
||||
}
|
||||
cont.conn = conn
|
||||
cont.client = cmapi.NewControlClient(conn)
|
||||
cont.client = cmctl.NewControlClient(conn)
|
||||
if cont.client == nil {
|
||||
return cont, fmt.Errorf("Nil control client")
|
||||
}
|
||||
@@ -66,30 +54,3 @@ func (cont *Control) Close() {
|
||||
cont.conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(access *Access) (cmapi.ControlClient, error) {
|
||||
var err error
|
||||
var cli cmapi.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 = cmapi.NewControlClient(conn)
|
||||
return cli, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user