[CI-SKIP] Store Pre-Claude Code
All checks were successful
Build (artifact) / build (push) Has been skipped
All checks were successful
Build (artifact) / build (push) Has been skipped
This commit is contained in:
@@ -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
17
app/server/commands.go
Normal 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{})
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -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
7
app/server/main.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello server")
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package server
|
||||
Reference in New Issue
Block a user