certmanager updates
This commit is contained in:
@@ -1,132 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"os"
|
||||
|
||||
"certmanager/pkg/client"
|
||||
cmapi "certmanager/pkg/cmctl"
|
||||
)
|
||||
|
||||
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 := &cmapi.CreateIssuerPairParams{
|
||||
IssuerCommonName: util.issuerCommonName,
|
||||
SignerID: util.signerID,
|
||||
}
|
||||
res, err = cli.CreateIssuerPair(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
certPEM, err := base64.StdEncoding.DecodeString(res.Certificate)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Certificate = string(certPEM)
|
||||
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
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 := &cmapi.RevokeIssuerPairParams{
|
||||
IssuerID: util.issuerID,
|
||||
IssuerName: util.issuerName,
|
||||
}
|
||||
res, err = cli.RevokeIssuerPair(ctx, params)
|
||||
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 := &cmapi.UnrevokeIssuerPairParams{
|
||||
IssuerID: util.issuerID,
|
||||
IssuerName: util.issuerName,
|
||||
}
|
||||
res, err = cli.UnrevokeIssuerPair(ctx, params)
|
||||
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 := &cmapi.ListIssuerPairsParams{}
|
||||
res, err = cli.ListIssuerPairs(ctx, params)
|
||||
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 := &cmapi.GetIssuerCertificateParams{
|
||||
IssuerID: util.issuerID,
|
||||
IssuerName: util.issuerName,
|
||||
}
|
||||
res, err = cli.GetIssuerCertificate(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
@@ -39,6 +39,11 @@ const (
|
||||
unrevokeServicePairCmd = "unrevokeServicePair"
|
||||
listServicePairsCmd = "listServicePairs"
|
||||
getServicePairCmd = "getServicePair"
|
||||
|
||||
createAccountCmd = "createAccount"
|
||||
updateAccountCmd = "updateAccount"
|
||||
deleteAccountCmd = "revokeAccount"
|
||||
listAccountsCmd = "listAccounts"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -70,6 +75,13 @@ type Util struct {
|
||||
serviceCommonName string
|
||||
serviceID int64
|
||||
serviceName string
|
||||
|
||||
accountID int64
|
||||
username string
|
||||
password string
|
||||
disable bool
|
||||
newUsername string
|
||||
newPassword string
|
||||
}
|
||||
|
||||
func NewUtil() *Util {
|
||||
@@ -114,17 +126,23 @@ 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\n",
|
||||
fmt.Printf("Command list: %s, %s, %s, %s, %s, %s\n",
|
||||
createIssuerPairCmd,
|
||||
importIssuerPairCmd,
|
||||
revokeIssuerPairCmd,
|
||||
unrevokeIssuerPairCmd,
|
||||
listIssuerPairsCmd,
|
||||
getIssuerCertificateCmd,
|
||||
getIssuerCertificateCmd)
|
||||
fmt.Printf("Command list: %s, %s, %s, %s\n",
|
||||
createServicePairCmd,
|
||||
revokeServicePairCmd,
|
||||
listServicePairsCmd,
|
||||
getServicePairCmd)
|
||||
fmt.Printf("Command list: %s, %s, %s, %s\n",
|
||||
createAccountCmd,
|
||||
deleteAccountCmd,
|
||||
listAccountsCmd,
|
||||
updateAccountCmd)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("Global options:\n")
|
||||
flag.PrintDefaults()
|
||||
@@ -342,6 +360,76 @@ func (util *Util) GetOpt() error {
|
||||
}
|
||||
flagSet.Parse(subArgs)
|
||||
util.subCmd = subCmd
|
||||
|
||||
case createAccountCmd:
|
||||
flagSet := flag.NewFlagSet(createAccountCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.StringVar(&util.username, "username", util.username, "user name")
|
||||
flagSet.StringVar(&util.password, "password", util.password, "user password")
|
||||
|
||||
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 deleteAccountCmd:
|
||||
flagSet := flag.NewFlagSet(deleteAccountCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.StringVar(&util.username, "username", util.username, "user name")
|
||||
flagSet.Int64Var(&util.accountID, "accountId", util.accountID, "account 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 listAccountsCmd:
|
||||
flagSet := flag.NewFlagSet(listAccountsCmd, 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 updateAccountCmd:
|
||||
flagSet := flag.NewFlagSet(updateAccountCmd, flag.ExitOnError)
|
||||
|
||||
flagSet.StringVar(&util.username, "username", util.username, "user name")
|
||||
flagSet.Int64Var(&util.accountID, "accountId", util.accountID, "account ID")
|
||||
|
||||
flagSet.StringVar(&util.newUsername, "username", util.newUsername, "new user name")
|
||||
flagSet.StringVar(&util.newPassword, "password", util.newPassword, "new user password")
|
||||
flagSet.BoolVar(&util.disable, "disable", util.disable, "disable account")
|
||||
|
||||
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")
|
||||
@@ -392,6 +480,16 @@ func (util *Util) Exec() error {
|
||||
res, err = util.ListServicePairs(ctx)
|
||||
case getServicePairCmd:
|
||||
res, err = util.GetServicePair(ctx)
|
||||
|
||||
case createAccountCmd:
|
||||
res, err = util.CreateAccount(ctx)
|
||||
case updateAccountCmd:
|
||||
res, err = util.UpdateAccount(ctx)
|
||||
case listAccountsCmd:
|
||||
res, err = util.ListAccounts(ctx)
|
||||
case deleteAccountCmd:
|
||||
res, err = util.DeleteAccount(ctx)
|
||||
|
||||
default:
|
||||
err = errors.New("Unknown cli command")
|
||||
}
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
|
||||
"certmanager/pkg/client"
|
||||
cmapi "certmanager/pkg/cmctl"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
inetAddresses := strings.Split(util.ipAdressesList, ",")
|
||||
hostnames := strings.Split(util.hostnameList, ",")
|
||||
|
||||
params := &cmapi.CreateServicePairParams{
|
||||
IssuerName: util.issuerName,
|
||||
IssuerID: util.issuerID,
|
||||
ServiceCommonName: util.serviceCommonName,
|
||||
InetAddresses: inetAddresses,
|
||||
Hostnames: hostnames,
|
||||
}
|
||||
res, err = cli.CreateServicePair(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
certPEM, err := base64.StdEncoding.DecodeString(res.Certificate)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Certificate = string(certPEM)
|
||||
keyPEM, err := base64.StdEncoding.DecodeString(res.Key)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Key = string(keyPEM)
|
||||
caPEM, err := base64.StdEncoding.DecodeString(res.IssuerCertificate)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.IssuerCertificate = string(caPEM)
|
||||
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{
|
||||
ServiceName: util.serviceName,
|
||||
ServiceID: util.serviceID,
|
||||
}
|
||||
res, err = cli.RevokeServicePair(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *Util) UnrevokeServicePair(ctx context.Context) (*cmapi.UnrevokeServicePairResult, error) {
|
||||
var err error
|
||||
res := &cmapi.UnrevokeServicePairResult{}
|
||||
cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
params := &cmapi.UnrevokeServicePairParams{
|
||||
ServiceName: util.serviceName,
|
||||
ServiceID: util.serviceID,
|
||||
}
|
||||
res, err = cli.UnrevokeServicePair(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{
|
||||
ServiceID: util.serviceID,
|
||||
ServiceName: util.serviceName,
|
||||
}
|
||||
res, err = cli.GetServicePair(ctx, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
certPEM, err := base64.StdEncoding.DecodeString(res.Certificate)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Certificate = string(certPEM)
|
||||
keyPEM, err := base64.StdEncoding.DecodeString(res.Key)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Key = string(keyPEM)
|
||||
caPEM, err := base64.StdEncoding.DecodeString(res.IssuerCertificate)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.IssuerCertificate = string(caPEM)
|
||||
return res, err
|
||||
}
|
||||
Reference in New Issue
Block a user