[CI-SKIP] Store Pre-Claude Code
All checks were successful
Build (artifact) / build (push) Has been skipped

This commit is contained in:
2026-04-22 22:26:21 -04:00
parent 727de333b4
commit 6aacbfbb71
30 changed files with 239 additions and 246 deletions

40
app/bundle/main.go Normal file
View File

@@ -0,0 +1,40 @@
package main
import (
"fmt"
"os"
"git.nevets.tech/Steven/certman/app"
"github.com/spf13/cobra"
)
//TODO create logic for gh vs gt repos
func main() {
rootCmd := &cobra.Command{
Use: "certman",
Short: "CertMan",
Long: "Certificate Manager",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
rootCmd.AddCommand(app.VersionCmd)
rootCmd.AddCommand(app.NewKeyCmd)
rootCmd.AddCommand(app.DevCmd)
rootCmd.AddCommand(app.NewDomainCmd)
rootCmd.AddCommand(app.InstallCmd)
rootCmd.AddCommand(app.CertCmd)
//rootCmd.AddCommand(executor.ExecutorCmd)
rootCmd.AddCommand(app.DaemonCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

View File

@@ -1,4 +1,4 @@
package shared
package app
import (
"github.com/spf13/cobra"

View File

@@ -1,10 +1,10 @@
package client
package main
import (
"fmt"
"path/filepath"
"git.nevets.tech/Steven/certman/app/shared"
"git.nevets.tech/Steven/certman/app"
"git.nevets.tech/Steven/certman/client"
"git.nevets.tech/Steven/certman/common"
"github.com/go-git/go-billy/v5/memfs"
@@ -43,7 +43,7 @@ var (
func init() {
renewCertSubCmd.AddCommand(updateCertLinkSubCmd, decryptCertsSubCmd)
shared.CertCmd.AddCommand(renewCertSubCmd)
app.CertCmd.AddCommand(renewCertSubCmd)
}
func renewCert(domain string) error {
@@ -52,25 +52,26 @@ func renewCert(domain string) error {
Storage: memory.NewStorage(),
FS: memfs.New(),
}
config := shared.Config()
domainConfig, exists := shared.DomainStore().Get(domain)
config := app.Config()
domainConfig, exists := app.DomainStore().Get(domain)
if !exists {
return shared.ErrConfigNotFound
return app.ErrConfigNotFound
}
if err := client.PullCerts(config, domainConfig, gitWorkspace); err != nil {
return err
}
certsDir := common.CertsDir(config, domainConfig)
certsDir := common.EffectiveDataRoot(config, domainConfig)
return client.DecryptAndWriteCertificates(certsDir, config, domainConfig, gitWorkspace)
}
func updateLinks(domain string) error {
domainConfig, exists := shared.DomainStore().Get(domain)
domainConfig, exists := app.DomainStore().Get(domain)
if !exists {
return fmt.Errorf("domain %s does not exist", domain)
}
certsDir := shared.DomainCertsDirWConf(domain, domainConfig)
effectiveDataRoot := common.EffectiveDataRoot(app.Config(), domainConfig)
certsDir := filepath.Join(effectiveDataRoot, "certificates", domain)
certLinks := domainConfig.Certificates.CertSymlinks
for _, certLink := range certLinks {
@@ -83,7 +84,7 @@ func updateLinks(domain string) error {
keyLinks := domainConfig.Certificates.KeySymlinks
for _, keyLink := range keyLinks {
err := common.LinkFile(filepath.Join(certsDir, domain+".crt"), keyLink, domain, ".key")
err := common.LinkFile(filepath.Join(certsDir, domain+".key"), keyLink, domain, ".key")
if err != nil {
fmt.Printf("Error linking cert %s to %s: %v", keyLink, domain, err)
continue

View File

@@ -1 +0,0 @@
package client

17
app/client/commands.go Normal file
View File

@@ -0,0 +1,17 @@
package main
import (
"git.nevets.tech/Steven/certman/app"
"github.com/spf13/cobra"
)
func init() {
app.DaemonCmd.AddCommand(&cobra.Command{
Use: "start",
Short: "Start the daemon",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return app.RunDaemonCmd(&Daemon{})
},
})
}

View File

@@ -1,4 +1,4 @@
package client
package main
import (
"fmt"
@@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"
appShared "git.nevets.tech/Steven/certman/app/shared"
"git.nevets.tech/Steven/certman/app"
"git.nevets.tech/Steven/certman/client"
"git.nevets.tech/Steven/certman/common"
"github.com/go-git/go-billy/v5/memfs"
@@ -18,7 +18,7 @@ type Daemon struct{}
func (d *Daemon) Init() {
fmt.Println("Starting CertManager in client mode...")
err := appShared.LoadDomainConfigs()
err := app.LoadDomainConfigs()
if err != nil {
log.Fatalf("Error loading domain configs: %v", err)
}
@@ -30,8 +30,8 @@ func (d *Daemon) Tick() {
fmt.Println("tick!")
// Get local copy of configs
config := appShared.Config()
localDomainConfigs := appShared.DomainStore().Snapshot()
config := app.Config()
localDomainConfigs := app.DomainStore().Snapshot()
// Loop over all domain configs (domains)
for domainStr, domainConfig := range localDomainConfigs {
@@ -44,17 +44,12 @@ func (d *Daemon) Tick() {
// If the repo doesn't exist, we can't check for a remote commit, so stop the rest of the check
repoExists := domainConfig.Internal.RepoExists
if repoExists {
var dataRoot string
if domainConfig.Certificates.DataRoot == "" {
config.Certificates.DataRoot = domainStr
} else {
dataRoot = domainConfig.Certificates.DataRoot
}
dataRoot := common.EffectiveDataRoot(config, domainConfig)
localHash, err := client.LocalCommitHash(domainStr, dataRoot)
if err != nil {
fmt.Printf("No local commit hash found for domain %s\n", domainStr)
}
gitSource, err := common.StrToGitSource(appShared.Config().Git.Host)
gitSource, err := common.StrToGitSource(app.Config().Git.Host)
if err != nil {
fmt.Printf("Error getting git source for domain %s: %v\n", domainStr, err)
continue
@@ -77,14 +72,15 @@ func (d *Daemon) Tick() {
}
// Ex: https://git.example.com/Org/Repo-suffix.git
// Clones repo and stores in gitWorkspace, skip if clone fails (doesn't exist?)
repoUrl := appShared.Config().Git.Server + "/" + config.Git.OrgName + "/" + domainStr + domainConfig.Repo.RepoSuffix + ".git"
repoUrl := app.Config().Git.Server + "/" + config.Git.OrgName + "/" + domainStr + domainConfig.Repo.RepoSuffix + ".git"
err := common.CloneRepo(repoUrl, gitWorkspace, common.Client, config)
if err != nil {
fmt.Printf("Error cloning domain repo %s: %v\n", domainStr, err)
continue
}
certsDir := appShared.DomainCertsDirWConf(domainStr, domainConfig)
effectiveDataRoot := common.EffectiveDataRoot(config, domainConfig)
certsDir := filepath.Join(effectiveDataRoot, "certificates", domainStr)
// Get files in repo
fileInfos, err := gitWorkspace.FS.ReadDir("/")
@@ -156,7 +152,7 @@ func (d *Daemon) Tick() {
func (d *Daemon) Reload() {
fmt.Println("Reloading configs...")
err := appShared.LoadDomainConfigs()
err := app.LoadDomainConfigs()
if err != nil {
fmt.Printf("Error loading domain configs: %v\n", err)
return

View File

@@ -1,4 +1,4 @@
package client
package main
import (
"context"
@@ -6,7 +6,7 @@ import (
"log"
"time"
"git.nevets.tech/Steven/certman/app/shared"
"git.nevets.tech/Steven/certman/app"
pb "git.nevets.tech/Steven/certman/proto/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
@@ -23,7 +23,7 @@ func SendHook(domain string) {
defer conn.Close()
client := pb.NewHookServiceClient(conn)
hooks, err := shared.PostPullHooks(domain)
hooks, err := app.PostPullHooks(domain)
if err != nil {
fmt.Printf("Error getting hooks: %v\n", err)
return

36
app/client/main.go Normal file
View File

@@ -0,0 +1,36 @@
package main
import (
"fmt"
"os"
"git.nevets.tech/Steven/certman/app"
"github.com/spf13/cobra"
)
func main() {
rootCmd := &cobra.Command{
Use: "certman",
Short: "CertMan",
Long: "Certificate Manager",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
rootCmd.AddCommand(app.VersionCmd)
rootCmd.AddCommand(app.NewKeyCmd)
rootCmd.AddCommand(app.DevCmd)
rootCmd.AddCommand(app.NewDomainCmd)
rootCmd.AddCommand(app.InstallCmd)
rootCmd.AddCommand(app.CertCmd)
rootCmd.AddCommand(app.DaemonCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

View File

@@ -1,4 +1,4 @@
package shared
package app
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package shared
package app
import (
"errors"
@@ -80,8 +80,6 @@ func Config() *common.AppConfig {
}
func DomainStore() *DomainConfigStore {
domainStore.mu.RLock()
defer domainStore.mu.RUnlock()
return domainStore
}

View File

@@ -1,4 +1,4 @@
package shared
package app
import (
"context"

View File

@@ -1,4 +1,4 @@
package executor
package main
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package executor
package main
import (
"fmt"

View File

@@ -1,4 +1,4 @@
package executor
package main
import (
"context"

7
app/executor/main.go Normal file
View File

@@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("Hello Executor")
}

View File

@@ -1,4 +1,4 @@
package executor
package main
import "fmt"

View File

@@ -1,11 +1,11 @@
package server
package main
import (
"fmt"
"path/filepath"
"time"
"git.nevets.tech/Steven/certman/app/shared"
"git.nevets.tech/Steven/certman/app"
"git.nevets.tech/Steven/certman/common"
"git.nevets.tech/Steven/certman/server"
"github.com/go-git/go-billy/v5/memfs"
@@ -27,17 +27,17 @@ var (
func init() {
renewCertSubCmd.Flags().BoolVar(&noPush, "no-push", false, "Don't push certs to repo, renew locally only [server mode only]")
shared.CertCmd.AddCommand(renewCertSubCmd)
app.CertCmd.AddCommand(renewCertSubCmd)
}
func renewCertCmd(domain string, noPush bool) error {
if err := shared.LoadConfig(); err != nil {
if err := app.LoadConfig(); err != nil {
return err
}
if err := shared.LoadDomainConfigs(); err != nil {
if err := app.LoadDomainConfigs(); err != nil {
return err
}
mgr, err := server.NewACMEManager(shared.Config())
mgr, err := server.NewACMEManager(app.Config())
if err != nil {
return err
}
@@ -50,8 +50,8 @@ func renewCertCmd(domain string, noPush bool) error {
}
func renewCerts(domain string, noPush bool, mgr *server.ACMEManager) error {
config := shared.Config()
domainConfig, exists := shared.DomainStore().Get(domain)
config := app.Config()
domainConfig, exists := app.DomainStore().Get(domain)
if !exists {
return fmt.Errorf("domain %s does not exist", domain)
}
@@ -66,7 +66,7 @@ func renewCerts(domain string, noPush bool, mgr *server.ACMEManager) error {
}
domainConfig.Internal.LastIssued = time.Now().UTC().Unix()
err = shared.WriteDomainConfig(domainConfig)
err = app.WriteDomainConfig(domainConfig)
if err != nil {
return fmt.Errorf("error saving domain config %s: %v", domain, err)
}
@@ -97,7 +97,7 @@ func renewCerts(domain string, noPush bool, mgr *server.ACMEManager) error {
return fmt.Errorf("error creating Gitea repo for domain %s", domain)
}
domainConfig.Internal.RepoExists = true
err = shared.WriteDomainConfig(domainConfig)
err = app.WriteDomainConfig(domainConfig)
if err != nil {
return fmt.Errorf("error saving domain config %s: %v", domain, err)
}

17
app/server/commands.go Normal file
View File

@@ -0,0 +1,17 @@
package main
import (
"git.nevets.tech/Steven/certman/app"
"github.com/spf13/cobra"
)
func init() {
app.DaemonCmd.AddCommand(&cobra.Command{
Use: "start",
Short: "Start the daemon",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return app.RunDaemonCmd(&Daemon{})
},
})
}

View File

@@ -1,13 +1,15 @@
package server
package main
import (
"errors"
"fmt"
"log"
"os"
"path/filepath"
"sync"
"time"
appShared "git.nevets.tech/Steven/certman/app/shared"
appShared "git.nevets.tech/Steven/certman/app"
"git.nevets.tech/Steven/certman/common"
"git.nevets.tech/Steven/certman/server"
"github.com/go-git/go-billy/v5/memfs"
@@ -63,6 +65,7 @@ func (d *Daemon) Tick() {
if !domainConfig.Domain.Enabled {
continue
}
//TODO: have renewPeriod logic default to use certificate expiry if available
renewPeriod := domainConfig.Certificates.RenewPeriod
lastIssued := time.Unix(domainConfig.Internal.LastIssued, 0).UTC()
renewalDue := lastIssued.AddDate(0, 0, renewPeriod)
@@ -70,12 +73,16 @@ func (d *Daemon) Tick() {
//TODO extra check if certificate expiry (create cache?)
_, err := d.ACMEManager.RenewForDomain(domainStr)
if err != nil {
// if no existing cert, obtain instead
_, err = d.ACMEManager.ObtainForDomain(domainStr, appShared.Config(), domainConfig)
if err != nil {
fmt.Printf("Error obtaining domain certificates for domain %s: %v\n", domainStr, err)
continue
if errors.Is(err, os.ErrNotExist) {
// if no existing cert, obtain instead
_, err = d.ACMEManager.ObtainForDomain(domainStr, appShared.Config(), domainConfig)
if err != nil {
fmt.Printf("Error obtaining domain certificates for domain %s: %v\n", domainStr, err)
continue
}
}
fmt.Printf("Error: %v\n", err)
continue
}
domainConfig.Internal.LastIssued = time.Now().UTC().Unix()

7
app/server/main.go Normal file
View File

@@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("Hello server")
}

View File

@@ -1 +0,0 @@
package server

View File

@@ -1 +0,0 @@
package shared

View File

@@ -1,11 +1,9 @@
package shared
package app
import (
"fmt"
"os"
"path/filepath"
"git.nevets.tech/Steven/certman/common"
"github.com/spf13/cobra"
)
@@ -51,18 +49,6 @@ func createFile(fileName string, filePermission os.FileMode, data []byte) {
}
}
// DomainCertsDirWConf Can return ErrBlankConfigEntry or other errors
func DomainCertsDirWConf(domain string, domainConfig *common.DomainConfig) string {
var effectiveDataRoot string
if domainConfig.Certificates.DataRoot == "" {
effectiveDataRoot = config.Certificates.DataRoot
} else {
effectiveDataRoot = domainConfig.Certificates.DataRoot
}
return filepath.Join(effectiveDataRoot, "certificates", domain)
}
func basicCmd(use, short string, commandFunc func(cmd *cobra.Command, args []string)) *cobra.Command {
return &cobra.Command{
Use: use,