certmanager updated
This commit is contained in:
@@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"os"
|
||||
|
||||
cmapi "certmanager/api/certmanagercontrol"
|
||||
"certmanager/pkg/client"
|
||||
@@ -14,8 +16,11 @@ func (util *Util) CreateIssuerPair(ctx context.Context) (*cmapi.CreateIssuerPair
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.createIssuerPairParams
|
||||
res, err = cli.CreateIssuerPair(ctx, ¶ms)
|
||||
params := &cmapi.CreateIssuerPairParams{
|
||||
IssuerCommonName: util.issuerCommonName,
|
||||
SignerID: util.signerID,
|
||||
}
|
||||
res, err = cli.CreateIssuerPair(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -29,8 +34,22 @@ func (util *Util) ImportIssuerPair(ctx context.Context) (*cmapi.ImportIssuerPair
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.importIssuerPairParams
|
||||
res, err = cli.ImportIssuerPair(ctx, ¶ms)
|
||||
certBytes, err := os.ReadFile(util.certFilename)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
cert := base64.StdEncoding.EncodeToString(certBytes)
|
||||
keyBytes, err := os.ReadFile(util.certFilename)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
key := base64.StdEncoding.EncodeToString(keyBytes)
|
||||
|
||||
params := &cmapi.ImportIssuerPairParams{
|
||||
Certificate: cert,
|
||||
Key: key,
|
||||
}
|
||||
res, err = cli.ImportIssuerPair(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -44,8 +63,11 @@ func (util *Util) RevokeIssuerPair(ctx context.Context) (*cmapi.RevokeIssuerPair
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.revokeIssuerPairParams
|
||||
res, err = cli.RevokeIssuerPair(ctx, ¶ms)
|
||||
params := &cmapi.RevokeIssuerPairParams{
|
||||
IssuerID: util.issuerID,
|
||||
IssuerName: util.issuerName,
|
||||
}
|
||||
res, err = cli.RevokeIssuerPair(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -59,8 +81,11 @@ func (util *Util) UnrevokeIssuerPair(ctx context.Context) (*cmapi.UnrevokeIssuer
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.unrevokeIssuerPairParams
|
||||
res, err = cli.UnrevokeIssuerPair(ctx, ¶ms)
|
||||
params := &cmapi.UnrevokeIssuerPairParams{
|
||||
IssuerID: util.issuerID,
|
||||
IssuerName: util.issuerName,
|
||||
}
|
||||
res, err = cli.UnrevokeIssuerPair(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -74,8 +99,8 @@ func (util *Util) ListIssuerPairs(ctx context.Context) (*cmapi.ListIssuerPairsRe
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.listIssuerPairsParams
|
||||
res, err = cli.ListIssuerPairs(ctx, ¶ms)
|
||||
params := &cmapi.ListIssuerPairsParams{}
|
||||
res, err = cli.ListIssuerPairs(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -89,68 +114,11 @@ func (util *Util) GetIssuerCertificate(ctx context.Context) (*cmapi.GetIssuerCer
|
||||
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)
|
||||
params := &cmapi.GetIssuerCertificateParams{
|
||||
IssuerID: util.issuerID,
|
||||
IssuerName: util.issuerName,
|
||||
}
|
||||
res, err = cli.GetIssuerCertificate(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -56,17 +56,20 @@ type Util struct {
|
||||
access client.Access
|
||||
cont *cmapi.ControlClient
|
||||
|
||||
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
|
||||
caFilenamesList string
|
||||
certFilename string
|
||||
hostnameList string
|
||||
ipAdressesList string
|
||||
issuerCommonName string
|
||||
issuerID int64
|
||||
issuerName string
|
||||
keyFilename string
|
||||
|
||||
signerID int64
|
||||
signerName string
|
||||
|
||||
serviceID int64
|
||||
serviceName string
|
||||
}
|
||||
|
||||
func NewUtil() *Util {
|
||||
@@ -111,7 +114,7 @@ func (util *Util) GetOpt() error {
|
||||
fmt.Printf("Usage: %s [option] command [command option]\n", exeName)
|
||||
fmt.Printf("\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",
|
||||
fmt.Printf("Command list: %s, %s, %s, %s, %s, %s, %s, %s, %s, %s\n",
|
||||
createIssuerPairCmd,
|
||||
importIssuerPairCmd,
|
||||
revokeIssuerPairCmd,
|
||||
@@ -160,6 +163,41 @@ func (util *Util) GetOpt() error {
|
||||
case createIssuerPairCmd:
|
||||
flagSet := flag.NewFlagSet(createIssuerPairCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.StringVar(&util.issuerCommonName, "cn", util.issuerCommonName, "new issuer canonic name")
|
||||
flagSet.Int64Var(&util.signerID, "signerID", util.signerID, "optional issuer ID for sign")
|
||||
flagSet.StringVar(&util.signerName, "signerName", util.signerName, "optional issuer name for sign")
|
||||
|
||||
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.StringVar(&util.issuerName, "issuerName", util.issuerName, "issuer name")
|
||||
flagSet.Int64Var(&util.issuerID, "issuerID", util.issuerID, "issuer ID")
|
||||
|
||||
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)
|
||||
@@ -188,6 +226,9 @@ func (util *Util) GetOpt() error {
|
||||
case revokeIssuerPairCmd:
|
||||
flagSet := flag.NewFlagSet(revokeIssuerPairCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.StringVar(&util.issuerName, "issuerName", util.issuerName, "issuer name")
|
||||
flagSet.Int64Var(&util.issuerID, "issuerID", util.issuerID, "issuer ID")
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Usage: %s [global options] %s [command options]\n", exeName, subCmd)
|
||||
@@ -202,33 +243,8 @@ func (util *Util) GetOpt() error {
|
||||
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.StringVar(&util.issuerName, "issuerName", util.issuerName, "issuer name")
|
||||
flagSet.Int64Var(&util.issuerID, "issuerID", util.issuerID, "issuer ID")
|
||||
|
||||
flagSet.Usage = func() {
|
||||
fmt.Printf("\n")
|
||||
@@ -325,6 +341,27 @@ func (util *Util) Exec() error {
|
||||
switch util.subCmd {
|
||||
case getStatusCmd:
|
||||
res, err = util.GetStatus(ctx)
|
||||
case createIssuerPairCmd:
|
||||
res, err = util.CreateIssuerPair(ctx)
|
||||
case importIssuerPairCmd:
|
||||
res, err = util.ImportIssuerPair(ctx)
|
||||
case revokeIssuerPairCmd:
|
||||
res, err = util.RevokeIssuerPair(ctx)
|
||||
case unrevokeIssuerPairCmd:
|
||||
res, err = util.UnrevokeIssuerPair(ctx)
|
||||
case listIssuerPairsCmd:
|
||||
res, err = util.ListIssuerPairs(ctx)
|
||||
case getIssuerCertificateCmd:
|
||||
res, err = util.GetIssuerCertificate(ctx)
|
||||
case createServicePairCmd:
|
||||
res, err = util.CreateServicePair(ctx)
|
||||
case revokeServicePairCmd:
|
||||
res, err = util.CreateServicePair(ctx)
|
||||
case listServicePairsCmd:
|
||||
res, err = util.ListServicePairs(ctx)
|
||||
case getServicePairCmd:
|
||||
res, err = util.GetServicePair(ctx)
|
||||
|
||||
default:
|
||||
err = errors.New("Unknown cli command")
|
||||
}
|
||||
@@ -349,8 +386,8 @@ func (util *Util) GetStatus(ctx context.Context) (*cmapi.GetStatusResult, error)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := util.getStatusParams
|
||||
res, err = cont.GetStatus(ctx, ¶ms)
|
||||
params := &cmapi.GetStatusParams{}
|
||||
res, err = cont.GetStatus(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
68
cmd/certmanagerctl/servicecli.go
Normal file
68
cmd/certmanagerctl/servicecli.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
cmapi "certmanager/api/certmanagercontrol"
|
||||
"certmanager/pkg/client"
|
||||
)
|
||||
|
||||
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 := &cmapi.CreateServicePairParams{}
|
||||
res, err = cli.CreateServicePair(ctx, params)
|
||||
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 := &cmapi.RevokeServicePairParams{}
|
||||
res, err = cli.RevokeServicePair(ctx, params)
|
||||
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 := &cmapi.ListServicePairsParams{}
|
||||
res, err = cli.ListServicePairs(ctx, params)
|
||||
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 := &cmapi.GetServicePairParams{}
|
||||
res, err = cli.GetServicePair(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
Reference in New Issue
Block a user