working changes
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,3 +9,5 @@ autom4te.cache/
|
||||
*.service
|
||||
tmp
|
||||
*.tar.*
|
||||
cmd/certmanagerctl/certmanagerctl
|
||||
cmd/certmanagerd/certmanagerd
|
||||
|
||||
1
cmd/certmanagerctl/.gitignore
vendored
1
cmd/certmanagerctl/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
lbmanagerctl*
|
||||
158
cmd/certmanagerctl/certman.go
Normal file
158
cmd/certmanagerctl/certman.go
Normal file
@@ -0,0 +1,158 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
cmapi "certmanager/api/certmanagercontrol"
|
||||
"certmanager/pkg/client"
|
||||
)
|
||||
|
||||
func (util *Util) CreateIssuerPair(ctx context.Context) (*cmapi.CreateIssuerPairResult, error) {
|
||||
var err error
|
||||
res := &cmapi.CreateIssuerPairResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.createIssuerPairParams
|
||||
res, err = cli.CreateIssuerPair(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *Util) ImportIssuerPair(ctx context.Context) (*cmapi.ImportIssuerPairResult, error) {
|
||||
var err error
|
||||
res := &cmapi.ImportIssuerPairResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.importIssuerPairParams
|
||||
res, err = cli.ImportIssuerPair(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *Util) RevokeIssuerPair(ctx context.Context) (*cmapi.RevokeIssuerPairResult, error) {
|
||||
var err error
|
||||
res := &cmapi.RevokeIssuerPairResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.revokeIssuerPairParams
|
||||
res, err = cli.RevokeIssuerPair(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *Util) UnrevokeIssuerPair(ctx context.Context) (*cmapi.UnrevokeIssuerPairResult, error) {
|
||||
var err error
|
||||
res := &cmapi.UnrevokeIssuerPairResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.unrevokeIssuerPairParams
|
||||
res, err = cli.UnrevokeIssuerPair(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *Util) ListIssuerPairs(ctx context.Context) (*cmapi.ListIssuerPairsResult, error) {
|
||||
var err error
|
||||
res := &cmapi.ListIssuerPairsResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.listIssuerPairsParams
|
||||
res, err = cli.ListIssuerPairs(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *Util) GetIssuerCertificate(ctx context.Context) (*cmapi.GetIssuerCertificateResult, error) {
|
||||
var err error
|
||||
res := &cmapi.GetIssuerCertificateResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.getIssuerCertificateParams
|
||||
res, err = cli.GetIssuerCertificate(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *Util) CreateServicePair(ctx context.Context) (*cmapi.CreateServicePairResult, error) {
|
||||
var err error
|
||||
res := &cmapi.CreateServicePairResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.createServicePairParams
|
||||
res, err = cli.CreateServicePair(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *Util) RevokeServicePair(ctx context.Context) (*cmapi.RevokeServicePairResult, error) {
|
||||
var err error
|
||||
res := &cmapi.RevokeServicePairResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.revokeServicePairParams
|
||||
res, err = cli.RevokeServicePair(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *Util) ListServicePairs(ctx context.Context) (*cmapi.ListServicePairsResult, error) {
|
||||
var err error
|
||||
res := &cmapi.ListServicePairsResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.listServicePairsParams
|
||||
res, err = cli.ListServicePairs(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *Util) GetServicePair(ctx context.Context) (*cmapi.GetServicePairResult, error) {
|
||||
var err error
|
||||
res := &cmapi.GetServicePairResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.getServicePairParams
|
||||
res, err = cli.GetServicePair(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
lbapi "certmanager/api/certmanagercontrol"
|
||||
cmapi "certmanager/api/certmanagercontrol"
|
||||
"certmanager/pkg/client"
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
@@ -27,6 +27,17 @@ const (
|
||||
|
||||
getStatusCmd = "getStatus"
|
||||
helpCmd = "help"
|
||||
|
||||
createIssuerPairCmd = "createIssuerPair"
|
||||
importIssuerPairCmd = "importIssuerPair"
|
||||
revokeIssuerPairCmd = "revokeIssuerPair"
|
||||
unrevokeIssuerPairCmd = "unrevokeIssuerPair"
|
||||
listIssuerPairsCmd = "listIssuerPairs"
|
||||
getIssuerCertificateCmd = "getIssuerCertificate"
|
||||
createServicePairCmd = "createServicePair"
|
||||
revokeServicePairCmd = "revokeServicePair"
|
||||
listServicePairsCmd = "listServicePairs"
|
||||
getServicePairCmd = "getServicePair"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -40,12 +51,22 @@ func main() {
|
||||
}
|
||||
|
||||
type Util struct {
|
||||
subCmd string
|
||||
cmdTimeout int64
|
||||
access client.Access
|
||||
cont *lbapi.ControlClient
|
||||
subCmd string
|
||||
cmdTimeout int64
|
||||
access client.Access
|
||||
cont *cmapi.ControlClient
|
||||
|
||||
getStatusParams lbapi.GetStatusParams
|
||||
getStatusParams cmapi.GetStatusParams
|
||||
createIssuerPairParams cmapi.CreateIssuerPairParams
|
||||
importIssuerPairParams cmapi.ImportIssuerPairParams
|
||||
revokeIssuerPairParams cmapi.RevokeIssuerPairParams
|
||||
unrevokeIssuerPairParams cmapi.UnrevokeIssuerPairParams
|
||||
listIssuerPairsParams cmapi.ListIssuerPairsParams
|
||||
getIssuerCertificateParams cmapi.GetIssuerCertificateParams
|
||||
createServicePairParams cmapi.CreateServicePairParams
|
||||
revokeServicePairParams cmapi.RevokeServicePairParams
|
||||
listServicePairsParams cmapi.ListServicePairsParams
|
||||
getServicePairParams cmapi.GetServicePairParams
|
||||
}
|
||||
|
||||
func NewUtil() *Util {
|
||||
@@ -89,7 +110,18 @@ func (util *Util) GetOpt() error {
|
||||
fmt.Println("")
|
||||
fmt.Printf("Usage: %s [option] command [command option]\n", exeName)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Command list: help, getStatus\n")
|
||||
fmt.Printf("Command list: help, %s\n", getStatusCmd)
|
||||
fmt.Printf("Command list: %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
|
||||
createIssuerPairCmd,
|
||||
importIssuerPairCmd,
|
||||
revokeIssuerPairCmd,
|
||||
unrevokeIssuerPairCmd,
|
||||
listIssuerPairsCmd,
|
||||
getIssuerCertificateCmd,
|
||||
createServicePairCmd,
|
||||
revokeServicePairCmd,
|
||||
listServicePairsCmd,
|
||||
getServicePairCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Global options:\n")
|
||||
flag.PrintDefaults()
|
||||
@@ -125,6 +157,146 @@ func (util *Util) GetOpt() error {
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case createIssuerPairCmd:
|
||||
flagSet := flag.NewFlagSet(createIssuerPairCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("The command options: none\n")
|
||||
flagSet.PrintDefaults()
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case importIssuerPairCmd:
|
||||
flagSet := flag.NewFlagSet(importIssuerPairCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("The command options: none\n")
|
||||
flagSet.PrintDefaults()
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case revokeIssuerPairCmd:
|
||||
flagSet := flag.NewFlagSet(revokeIssuerPairCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("The command options: none\n")
|
||||
flagSet.PrintDefaults()
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case unrevokeIssuerPairCmd:
|
||||
flagSet := flag.NewFlagSet(unrevokeIssuerPairCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("The command options: none\n")
|
||||
flagSet.PrintDefaults()
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case listIssuerPairsCmd:
|
||||
flagSet := flag.NewFlagSet(listIssuerPairsCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("The command options: none\n")
|
||||
flagSet.PrintDefaults()
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case getIssuerCertificateCmd:
|
||||
flagSet := flag.NewFlagSet(getIssuerCertificateCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("The command options: none\n")
|
||||
flagSet.PrintDefaults()
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case createServicePairCmd:
|
||||
flagSet := flag.NewFlagSet(createServicePairCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("The command options: none\n")
|
||||
flagSet.PrintDefaults()
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case revokeServicePairCmd:
|
||||
flagSet := flag.NewFlagSet(revokeServicePairCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("The command options: none\n")
|
||||
flagSet.PrintDefaults()
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case listServicePairsCmd:
|
||||
flagSet := flag.NewFlagSet(listServicePairsCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("The command options: none\n")
|
||||
flagSet.PrintDefaults()
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case getServicePairCmd:
|
||||
flagSet := flag.NewFlagSet(getServicePairCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("The command options: none\n")
|
||||
flagSet.PrintDefaults()
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
default:
|
||||
help()
|
||||
return errors.New("Unknown command")
|
||||
@@ -170,18 +342,17 @@ func (util *Util) Exec() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (util *Util) GetStatus(ctx context.Context) (*lbapi.GetStatusResult, error) {
|
||||
func (util *Util) GetStatus(ctx context.Context) (*cmapi.GetStatusResult, error) {
|
||||
var err error
|
||||
res := &lbapi.GetStatusResult{}
|
||||
res := &cmapi.GetStatusResult{}
|
||||
cont, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
req := util.getStatusParams
|
||||
res, err = cont.GetStatus(ctx, &req)
|
||||
params := util.getStatusParams
|
||||
res, err = cont.GetStatus(ctx, ¶ms)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
78
internal/grpc/handler/certman.go
Normal file
78
internal/grpc/handler/certman.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"certmanager/api/certmanagercontrol"
|
||||
)
|
||||
|
||||
|
||||
func (hand *Handler) CreateIssuerPair(ctx context.Context, req *certmanagercontrol.CreateIssuerPairParams) (*certmanagercontrol.CreateIssuerPairResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle CreateIssuerPair request")
|
||||
res, err := hand.lg.CreateIssuerPair(ctx, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (hand *Handler) ImportIssuerPair(ctx context.Context, req *certmanagercontrol.ImportIssuerPairParams) (*certmanagercontrol.ImportIssuerPairResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle ImportIssuerPair request")
|
||||
res, err := hand.lg.ImportIssuerPair(ctx, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (hand *Handler) RevokeIssuerPair(ctx context.Context, req *certmanagercontrol.RevokeIssuerPairParams) (*certmanagercontrol.RevokeIssuerPairResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle RevokeIssuerPair request")
|
||||
res, err := hand.lg.RevokeIssuerPair(ctx, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (hand *Handler) UnrevokeIssuerPair(ctx context.Context, req *certmanagercontrol.UnrevokeIssuerPairParams) (*certmanagercontrol.UnrevokeIssuerPairResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle UnrevokeIssuerPair request")
|
||||
res, err := hand.lg.UnrevokeIssuerPair(ctx, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (hand *Handler) ListIssuerPairs(ctx context.Context, req *certmanagercontrol.ListIssuerPairsParams) (*certmanagercontrol.ListIssuerPairsResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle ListIssuerPairs request")
|
||||
res, err := hand.lg.ListIssuerPairs(ctx, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (hand *Handler) GetIssuerCertificate(ctx context.Context, req *certmanagercontrol.GetIssuerCertificateParams) (*certmanagercontrol.GetIssuerCertificateResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle GetIssuerCertificate request")
|
||||
res, err := hand.lg.GetIssuerCertificate(ctx, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (hand *Handler) CreateServicePair(ctx context.Context, req *certmanagercontrol.CreateServicePairParams) (*certmanagercontrol.CreateServicePairResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle CreateServicePair request")
|
||||
res, err := hand.lg.CreateServicePair(ctx, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (hand *Handler) RevokeServicePair(ctx context.Context, req *certmanagercontrol.RevokeServicePairParams) (*certmanagercontrol.RevokeServicePairResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle RevokeServicePair request")
|
||||
res, err := hand.lg.RevokeServicePair(ctx, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (hand *Handler) ListServicePairs(ctx context.Context, req *certmanagercontrol.ListServicePairsParams) (*certmanagercontrol.ListServicePairsResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle ListServicePairs request")
|
||||
res, err := hand.lg.ListServicePairs(ctx, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (hand *Handler) GetServicePair(ctx context.Context, req *certmanagercontrol.GetServicePairParams) (*certmanagercontrol.GetServicePairResult, error) {
|
||||
var err error
|
||||
hand.log.Debugf("Handle GetServicePair request")
|
||||
res, err := hand.lg.GetServicePair(ctx, req)
|
||||
return res, err
|
||||
}
|
||||
67
internal/logic/certman.go
Normal file
67
internal/logic/certman.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"certmanager/api/certmanagercontrol"
|
||||
)
|
||||
|
||||
func (lg *Logic) CreateIssuerPair(ctx context.Context, params *certmanagercontrol.CreateIssuerPairParams) (*certmanagercontrol.CreateIssuerPairResult, error) {
|
||||
var err error
|
||||
res := &certmanagercontrol.CreateIssuerPairResult{}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) ImportIssuerPair(ctx context.Context, params *certmanagercontrol.ImportIssuerPairParams) (*certmanagercontrol.ImportIssuerPairResult, error) {
|
||||
var err error
|
||||
res := &certmanagercontrol.ImportIssuerPairResult{}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) RevokeIssuerPair(ctx context.Context, params *certmanagercontrol.RevokeIssuerPairParams) (*certmanagercontrol.RevokeIssuerPairResult, error) {
|
||||
var err error
|
||||
res := &certmanagercontrol.RevokeIssuerPairResult{}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) UnrevokeIssuerPair(ctx context.Context, params *certmanagercontrol.UnrevokeIssuerPairParams) (*certmanagercontrol.UnrevokeIssuerPairResult, error) {
|
||||
var err error
|
||||
res := &certmanagercontrol.UnrevokeIssuerPairResult{}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) ListIssuerPairs(ctx context.Context, params *certmanagercontrol.ListIssuerPairsParams) (*certmanagercontrol.ListIssuerPairsResult, error) {
|
||||
var err error
|
||||
res := &certmanagercontrol.ListIssuerPairsResult{}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) GetIssuerCertificate(ctx context.Context, params *certmanagercontrol.GetIssuerCertificateParams) (*certmanagercontrol.GetIssuerCertificateResult, error) {
|
||||
var err error
|
||||
res := &certmanagercontrol.GetIssuerCertificateResult{}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) CreateServicePair(ctx context.Context, params *certmanagercontrol.CreateServicePairParams) (*certmanagercontrol.CreateServicePairResult, error) {
|
||||
var err error
|
||||
res := &certmanagercontrol.CreateServicePairResult{}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) RevokeServicePair(ctx context.Context, params *certmanagercontrol.RevokeServicePairParams) (*certmanagercontrol.RevokeServicePairResult, error) {
|
||||
var err error
|
||||
res := &certmanagercontrol.RevokeServicePairResult{}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) ListServicePairs(ctx context.Context, params *certmanagercontrol.ListServicePairsParams) (*certmanagercontrol.ListServicePairsResult, error) {
|
||||
var err error
|
||||
res := &certmanagercontrol.ListServicePairsResult{}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (lg *Logic) GetServicePair(ctx context.Context, params *certmanagercontrol.GetServicePairParams) (*certmanagercontrol.GetServicePairResult, error) {
|
||||
var err error
|
||||
res := &certmanagercontrol.GetServicePairResult{}
|
||||
return res, err
|
||||
}
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"certmanager/api/certmanagercontrol"
|
||||
)
|
||||
|
||||
func (lg *Logic) GetStatus(ctx context.Context, nReq *certmanagercontrol.GetStatusParams) (*certmanagercontrol.GetStatusResult, error) {
|
||||
func (lg *Logic) GetStatus(ctx context.Context, params *certmanagercontrol.GetStatusParams) (*certmanagercontrol.GetStatusResult, error) {
|
||||
var err error
|
||||
nRes := &certmanagercontrol.GetStatusResult{
|
||||
res := &certmanagercontrol.GetStatusResult{
|
||||
Message: "Hello",
|
||||
}
|
||||
return nRes, err
|
||||
return res, err
|
||||
}
|
||||
|
||||
19
pkg/auxgrpc/error.go
Normal file
19
pkg/auxgrpc/error.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package auxgrpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func FmtError(err error) error {
|
||||
if err != nil {
|
||||
st, ok := status.FromError(err)
|
||||
if !ok {
|
||||
return err
|
||||
}
|
||||
err := fmt.Errorf("Return code %d, %s", st.Code(), st.Message())
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
159
pkg/client/certman.go
Normal file
159
pkg/client/certman.go
Normal file
@@ -0,0 +1,159 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
cmapi "certmanager/api/certmanagercontrol"
|
||||
"certmanager/pkg/auxgrpc"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
@@ -6,16 +6,15 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"certmanager/api/certmanagercontrol"
|
||||
//"certmanager/internal/config"
|
||||
cmapi "certmanager/api/certmanagercontrol"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultWrpcPort int = 20107
|
||||
DefaultGrpcPort int = 20108
|
||||
DefaultWrpcPort int = 20311
|
||||
DefaultGrpcPort int = 20312
|
||||
)
|
||||
|
||||
type Access struct {
|
||||
@@ -25,20 +24,59 @@ type Access struct {
|
||||
Password string
|
||||
}
|
||||
|
||||
func NewClient(access *Access) (certmanagercontrol.ControlClient, error) {
|
||||
var err error
|
||||
var cli certmanagercontrol.ControlClient
|
||||
|
||||
if access.Port == 0 {
|
||||
access.Port = DefaultGrpcPort
|
||||
}
|
||||
type Control struct {
|
||||
conn *grpc.ClientConn
|
||||
client cmapi.ControlClient
|
||||
}
|
||||
|
||||
func NewControl(access *Access) (*Control, error) {
|
||||
var err error
|
||||
cont := &Control{}
|
||||
|
||||
tlsConfig := &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
|
||||
const dialTimeout time.Duration = 5 * time.Second
|
||||
const idleTimeout time.Duration = 10 * time.Second
|
||||
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 cont, fmt.Errorf("Dial error: %v", err)
|
||||
}
|
||||
cont.conn = conn
|
||||
cont.client = cmapi.NewControlClient(conn)
|
||||
if cont.client == nil {
|
||||
return cont, fmt.Errorf("Nil control client")
|
||||
}
|
||||
return cont, err
|
||||
}
|
||||
|
||||
func (cont *Control) Close() {
|
||||
if cont.client != nil {
|
||||
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{
|
||||
@@ -53,6 +91,6 @@ func NewClient(access *Access) (certmanagercontrol.ControlClient, error) {
|
||||
if err != nil {
|
||||
return cli, fmt.Errorf("Dial error: %v", err)
|
||||
}
|
||||
cli = certmanagercontrol.NewControlClient(conn)
|
||||
cli = cmapi.NewControlClient(conn)
|
||||
return cli, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user