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

@@ -1,159 +0,0 @@
package client
import (
"context"
"time"
"certmanager/pkg/auxgrpc"
cmapi "certmanager/pkg/cmctl"
)
func (cont *Control) CreateIssuerPair(ctx context.Context, param *cmapi.CreateIssuerPairParams) (*cmapi.CreateIssuerPairResult, error) {
var err error
res := &cmapi.CreateIssuerPairResult{}
const timeout time.Duration = 50 * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
res, err = cont.client.CreateIssuerPair(ctx, param)
err = auxgrpc.FmtError(err)
if err != nil {
return res, err
}
return res, err
}
func (cont *Control) ImportIssuerPair(ctx context.Context, param *cmapi.ImportIssuerPairParams) (*cmapi.ImportIssuerPairResult, error) {
var err error
res := &cmapi.ImportIssuerPairResult{}
const timeout time.Duration = 50 * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
res, err = cont.client.ImportIssuerPair(ctx, param)
err = auxgrpc.FmtError(err)
if err != nil {
return res, err
}
return res, err
}
func (cont *Control) RevokeIssuerPair(ctx context.Context, param *cmapi.RevokeIssuerPairParams) (*cmapi.RevokeIssuerPairResult, error) {
var err error
res := &cmapi.RevokeIssuerPairResult{}
const timeout time.Duration = 50 * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
res, err = cont.client.RevokeIssuerPair(ctx, param)
err = auxgrpc.FmtError(err)
if err != nil {
return res, err
}
return res, err
}
func (cont *Control) UnrevokeIssuerPair(ctx context.Context, param *cmapi.UnrevokeIssuerPairParams) (*cmapi.UnrevokeIssuerPairResult, error) {
var err error
res := &cmapi.UnrevokeIssuerPairResult{}
const timeout time.Duration = 50 * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
res, err = cont.client.UnrevokeIssuerPair(ctx, param)
err = auxgrpc.FmtError(err)
if err != nil {
return res, err
}
return res, err
}
func (cont *Control) ListIssuerPairs(ctx context.Context, param *cmapi.ListIssuerPairsParams) (*cmapi.ListIssuerPairsResult, error) {
var err error
res := &cmapi.ListIssuerPairsResult{}
const timeout time.Duration = 50 * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
res, err = cont.client.ListIssuerPairs(ctx, param)
err = auxgrpc.FmtError(err)
if err != nil {
return res, err
}
return res, err
}
func (cont *Control) GetIssuerCertificate(ctx context.Context, param *cmapi.GetIssuerCertificateParams) (*cmapi.GetIssuerCertificateResult, error) {
var err error
res := &cmapi.GetIssuerCertificateResult{}
const timeout time.Duration = 50 * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
res, err = cont.client.GetIssuerCertificate(ctx, param)
err = auxgrpc.FmtError(err)
if err != nil {
return res, err
}
return res, err
}
func (cont *Control) CreateServicePair(ctx context.Context, param *cmapi.CreateServicePairParams) (*cmapi.CreateServicePairResult, error) {
var err error
res := &cmapi.CreateServicePairResult{}
const timeout time.Duration = 50 * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
res, err = cont.client.CreateServicePair(ctx, param)
err = auxgrpc.FmtError(err)
if err != nil {
return res, err
}
return res, err
}
func (cont *Control) RevokeServicePair(ctx context.Context, param *cmapi.RevokeServicePairParams) (*cmapi.RevokeServicePairResult, error) {
var err error
res := &cmapi.RevokeServicePairResult{}
const timeout time.Duration = 50 * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
res, err = cont.client.RevokeServicePair(ctx, param)
err = auxgrpc.FmtError(err)
if err != nil {
return res, err
}
return res, err
}
func (cont *Control) ListServicePairs(ctx context.Context, param *cmapi.ListServicePairsParams) (*cmapi.ListServicePairsResult, error) {
var err error
res := &cmapi.ListServicePairsResult{}
const timeout time.Duration = 50 * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
res, err = cont.client.ListServicePairs(ctx, param)
err = auxgrpc.FmtError(err)
if err != nil {
return res, err
}
return res, err
}
func (cont *Control) GetServicePair(ctx context.Context, param *cmapi.GetServicePairParams) (*cmapi.GetServicePairResult, error) {
var err error
res := &cmapi.GetServicePairResult{}
const timeout time.Duration = 50 * time.Second
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
res, err = cont.client.GetServicePair(ctx, param)
err = auxgrpc.FmtError(err)
if err != nil {
return res, err
}
return res, err
}

51
pkg/client/client.go Normal file
View 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
}

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
}