Major refactoring, updated config structure
This commit is contained in:
46
main.go
46
main.go
@@ -1,24 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"sync"
|
||||
|
||||
"git.nevets.tech/Keys/CertManager/commands"
|
||||
"git.nevets.tech/Keys/CertManager/internal"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var version = "1.0.0"
|
||||
var build = "1"
|
||||
|
||||
var (
|
||||
configFile string
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
wg sync.WaitGroup
|
||||
)
|
||||
var configFile string
|
||||
|
||||
var fqdnRegex = regexp.MustCompile(`^(?i:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$`)
|
||||
|
||||
@@ -36,9 +28,9 @@ func main() {
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "/etc/certman/certman.conf", "Configuration file")
|
||||
|
||||
rootCmd.AddCommand(basicCmd("version", "Show version", versionResponse))
|
||||
rootCmd.AddCommand(basicCmd("gen-key", "Generates encryption key", newKey))
|
||||
rootCmd.AddCommand(basicCmd("dev", "Dev Function", devFunc))
|
||||
rootCmd.AddCommand(basicCmd("version", "Show version", commands.VersionCmd))
|
||||
rootCmd.AddCommand(basicCmd("gen-key", "Generates encryption key", commands.NewKeyCmd))
|
||||
rootCmd.AddCommand(basicCmd("dev", "Dev Function", commands.DevCmd))
|
||||
|
||||
var domainCertDir string
|
||||
newDomainCmd := &cobra.Command{
|
||||
@@ -49,7 +41,7 @@ func main() {
|
||||
SilenceErrors: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
dirOverridden := cmd.Flags().Changed("dir")
|
||||
return newDomain(args[0], domainCertDir, dirOverridden)
|
||||
return commands.NewDomainCmd(args[0], domainCertDir, dirOverridden)
|
||||
},
|
||||
}
|
||||
newDomainCmd.Flags().StringVar(&domainCertDir, "dir", "/var/local/certman/certificates/", "Alternate directory for certificates")
|
||||
@@ -65,7 +57,7 @@ func main() {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
switch modeFlag {
|
||||
case "server", "client":
|
||||
return install(thinInstallFlag, modeFlag)
|
||||
return commands.InstallCmd(thinInstallFlag, modeFlag)
|
||||
default:
|
||||
return fmt.Errorf("invalid --mode %q (must be server or client)", modeFlag)
|
||||
}
|
||||
@@ -89,12 +81,22 @@ func main() {
|
||||
Short: "Renews a domains certificate",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return renewCertFunc(args[0], noPush)
|
||||
return commands.RenewCertCmd(args[0], noPush, internal.Server)
|
||||
},
|
||||
}
|
||||
renewCertCmd.Flags().BoolVar(&noPush, "no-push", false, "Don't push certs to repo, renew locally only [server mode only]")
|
||||
certCmd.AddCommand(renewCertCmd)
|
||||
|
||||
updateCertLinkCmd := &cobra.Command{
|
||||
Use: "update-link",
|
||||
Short: "Update linked certificates",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return commands.UpdateLinksCmd(args[0])
|
||||
},
|
||||
}
|
||||
certCmd.AddCommand(updateCertLinkCmd)
|
||||
|
||||
rootCmd.AddCommand(certCmd)
|
||||
|
||||
daemonCmd := &cobra.Command{
|
||||
@@ -110,7 +112,7 @@ func main() {
|
||||
Short: "Start the daemon",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runDaemon()
|
||||
return commands.RunDaemonCmd()
|
||||
},
|
||||
})
|
||||
|
||||
@@ -119,7 +121,7 @@ func main() {
|
||||
Short: "Stop the daemon",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return stopDaemon()
|
||||
return commands.StopDaemonCmd()
|
||||
},
|
||||
})
|
||||
|
||||
@@ -128,7 +130,7 @@ func main() {
|
||||
Short: "Reload daemon configs",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return reloadDaemon()
|
||||
return commands.ReloadDaemonCmd()
|
||||
},
|
||||
})
|
||||
|
||||
@@ -137,7 +139,7 @@ func main() {
|
||||
Short: "Manually triggers daemon tick",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return tickDaemon()
|
||||
return commands.TickDaemonCmd()
|
||||
},
|
||||
})
|
||||
|
||||
@@ -146,7 +148,7 @@ func main() {
|
||||
Short: "Show daemon status",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return statusDaemon()
|
||||
return commands.DaemonStatusCmd()
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user