Migrated to cobra for command handling and viper for config handling

This commit is contained in:
2026-02-25 21:17:23 +01:00
parent 61b65bf81c
commit 9eeb7a6ec0
13 changed files with 646 additions and 580 deletions

View File

@@ -7,45 +7,41 @@ import (
"path/filepath"
"strings"
"git.nevets.tech/Steven/ezconf"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5/storage/memory"
)
func initClient() {
err := loadDomainConfigs()
err := LoadDomainConfigs()
if err != nil {
log.Fatalf("Error loading domain configs: %v", err)
}
clientTick()
}
func clientTick() {
fmt.Println("Tick!")
// Get local copy of domain configs
mu.RLock()
localDomainConfigs := make(map[string]*ezconf.Configuration, len(domainConfigs))
for k, v := range domainConfigs {
localDomainConfigs[k] = v
}
mu.RUnlock()
localDomainConfigs := domainStore.Snapshot()
// Loop over all domain configs (domains)
for domainStr, domainConfig := range localDomainConfigs {
// Skip non-enabled domains
if !domainConfig.GetAsBoolean("Domain.enabled") {
if !domainConfig.GetBool("Domain.enabled") {
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.GetAsBoolean("Internal.repo_exists")
repoExists := domainConfig.GetBool("Internal.repo_exists")
if repoExists {
localHash, err := getLocalCommitHash(domainStr)
if err != nil {
fmt.Printf("No local commit hash found for domain %s\n", domainStr)
}
gitSource, err := strToGitSource(config.GetAsString("Git.host"))
gitSource, err := strToGitSource(config.GetString("Git.host"))
if err != nil {
fmt.Printf("Error getting git source for domain %s: %v\n", domainStr, err)
continue
@@ -68,7 +64,7 @@ func clientTick() {
}
// Ex: https://git.example.com/Org/Repo-suffix.git
// Clones repo and stores in gitWorkspace, skip if clone fails (doesn't exist?)
repoUrl := config.GetAsString("Git.server") + "/" + config.GetAsString("Git.org_name") + "/" + domainStr + domainConfig.GetAsString("Repo.repo_suffix") + ".git"
repoUrl := config.GetString("Git.server") + "/" + config.GetString("Git.org_name") + "/" + domainStr + domainConfig.GetString("Repo.repo_suffix") + ".git"
err := cloneRepo(repoUrl, gitWorkspace)
if err != nil {
fmt.Printf("Error cloning domain repo %s: %v\n", domainStr, err)
@@ -108,7 +104,7 @@ func clientTick() {
continue
}
err = DecryptFileFromBytes(domainConfig.GetAsString("Certificates.crypto_key"), fileBytes, filepath.Join(certsDir, filename), nil)
err = DecryptFileFromBytes(domainConfig.GetString("Certificates.crypto_key"), fileBytes, filepath.Join(certsDir, filename), nil)
if err != nil {
fmt.Printf("Error decrypting file %s in domain %s: %v\n", filename, domainStr, err)
continue
@@ -133,7 +129,7 @@ func clientTick() {
func reloadClient() {
fmt.Println("Reloading configs...")
err := loadDomainConfigs()
err := LoadDomainConfigs()
if err != nil {
fmt.Printf("Error loading domain configs: %v\n", err)
return