certmanager updates

This commit is contained in:
Олег Бородин
2024-08-10 10:19:56 +02:00
parent a21b4e2db9
commit 1cdbd2b034
29 changed files with 2341 additions and 1088 deletions

View File

@@ -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
}