Refactored config system again
All checks were successful
Build (artifact) / build (push) Successful in 27s
All checks were successful
Build (artifact) / build (push) Successful in 27s
This commit is contained in:
@@ -48,7 +48,7 @@ func init() {
|
||||
|
||||
func renewCert(domain string) error {
|
||||
config := app.Config()
|
||||
domainConfig, exists := app.DomainStore().Get(domain)
|
||||
domainConfig, exists := app.ClientDomainStore().Get(domain)
|
||||
if !exists {
|
||||
return app.ErrConfigNotFound
|
||||
}
|
||||
@@ -62,17 +62,17 @@ func renewCert(domain string) error {
|
||||
if err := client.PullCerts(config, gitWorkspace); err != nil {
|
||||
return err
|
||||
}
|
||||
certsDir := common.EffectiveDataRoot(config, domainConfig)
|
||||
certsDir := common.EffectiveDataRoot(config, domainConfig.Certificates.DataRoot)
|
||||
return client.DecryptAndWriteCertificates(certsDir, config, domainConfig, gitWorkspace)
|
||||
}
|
||||
|
||||
func updateLinks(domain string) error {
|
||||
domainConfig, exists := app.DomainStore().Get(domain)
|
||||
domainConfig, exists := app.ClientDomainStore().Get(domain)
|
||||
if !exists {
|
||||
return fmt.Errorf("domain %s does not exist", domain)
|
||||
}
|
||||
|
||||
effectiveDataRoot := common.EffectiveDataRoot(app.Config(), domainConfig)
|
||||
effectiveDataRoot := common.EffectiveDataRoot(app.Config(), domainConfig.Certificates.DataRoot)
|
||||
certsDir := filepath.Join(effectiveDataRoot, "certificates", domain)
|
||||
|
||||
certLinks := domainConfig.Certificates.CertSymlinks
|
||||
|
||||
@@ -18,7 +18,7 @@ type Daemon struct{}
|
||||
|
||||
func (d *Daemon) Init() {
|
||||
fmt.Println("Starting CertManager in client mode...")
|
||||
err := app.LoadDomainConfigs()
|
||||
err := app.LoadClientDomainConfigs()
|
||||
if err != nil {
|
||||
log.Fatalf("Error loading domain configs: %v", err)
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func (d *Daemon) Tick() {
|
||||
|
||||
// Get local copy of configs
|
||||
config := app.Config()
|
||||
localDomainConfigs := app.DomainStore().Snapshot()
|
||||
localDomainConfigs := app.ClientDomainStore().Snapshot()
|
||||
|
||||
// Loop over all domain configs (domains)
|
||||
for domainStr, domainConfig := range localDomainConfigs {
|
||||
@@ -40,32 +40,6 @@ func (d *Daemon) Tick() {
|
||||
continue
|
||||
}
|
||||
|
||||
// Skip domains with up-to-date commit hashes
|
||||
// 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 {
|
||||
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(app.Config().Git.Host)
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting git source for domain %s: %v\n", domainStr, err)
|
||||
continue
|
||||
}
|
||||
remoteHash, err := client.RemoteCommitHash(domainStr, gitSource, config, domainConfig)
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting remote commit hash for domain %s: %v\n", domainStr, err)
|
||||
}
|
||||
// If both hashes are blank (errored), break
|
||||
// If localHash equals remoteHash (local is up-to-date), skip
|
||||
if !(localHash == "" && remoteHash == "") && localHash == remoteHash {
|
||||
fmt.Printf("Domain %s is up to date. Skipping...\n", domainStr)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
gitWorkspace := &common.GitWorkspace{
|
||||
Domain: domainStr,
|
||||
URL: app.Config().Git.Server + "/" + config.Git.OrgName + "/" + domainStr + domainConfig.Repo.RepoSuffix + ".git",
|
||||
@@ -80,7 +54,7 @@ func (d *Daemon) Tick() {
|
||||
continue
|
||||
}
|
||||
|
||||
effectiveDataRoot := common.EffectiveDataRoot(config, domainConfig)
|
||||
effectiveDataRoot := common.EffectiveDataRoot(config, domainConfig.Certificates.DataRoot)
|
||||
certsDir := filepath.Join(effectiveDataRoot, "certificates", domainStr)
|
||||
|
||||
// Get files in repo
|
||||
@@ -122,7 +96,7 @@ func (d *Daemon) Tick() {
|
||||
continue
|
||||
}
|
||||
|
||||
dataRoot := common.EffectiveDataRoot(config, domainConfig)
|
||||
dataRoot := common.EffectiveDataRoot(config, domainConfig.Certificates.DataRoot)
|
||||
err = client.WriteCommitHash(headRef.Hash().String(), dataRoot)
|
||||
if err != nil {
|
||||
fmt.Printf("Error writing commit hash: %v\n", err)
|
||||
@@ -154,7 +128,7 @@ func (d *Daemon) Tick() {
|
||||
func (d *Daemon) Reload() {
|
||||
fmt.Println("Reloading configs...")
|
||||
|
||||
err := app.LoadDomainConfigs()
|
||||
err := app.LoadClientDomainConfigs()
|
||||
if err != nil {
|
||||
fmt.Printf("Error loading domain configs: %v\n", err)
|
||||
return
|
||||
|
||||
@@ -3,36 +3,13 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"git.nevets.tech/Steven/certman/app"
|
||||
pb "git.nevets.tech/Steven/certman/proto/v1"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
func SendHook(domain string) {
|
||||
conn, err := grpc.NewClient(
|
||||
"unix:///run/certman.sock",
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("fail to dial: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
client := pb.NewHookServiceClient(conn)
|
||||
|
||||
hooks, err := app.PostPullHooks(domain)
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting hooks: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, hook := range hooks {
|
||||
sendHook(client, hook)
|
||||
}
|
||||
}
|
||||
// SendHook is currently a no-op pending hook config modeling on ClientDomainConfig.
|
||||
func SendHook(domain string) {}
|
||||
|
||||
func sendHook(client pb.HookServiceClient, hook *pb.Hook) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
|
||||
@@ -20,6 +20,7 @@ func main() {
|
||||
|
||||
rootCmd.AddCommand(app.VersionCmd)
|
||||
rootCmd.AddCommand(app.NewKeyCmd)
|
||||
rootCmd.AddCommand(app.UpdateCmd)
|
||||
rootCmd.AddCommand(app.DevCmd)
|
||||
|
||||
rootCmd.AddCommand(app.NewDomainCmd)
|
||||
|
||||
Reference in New Issue
Block a user