Fix certificates not loading when key file exists

This commit is contained in:
Melon 2023-07-16 21:17:15 +01:00
parent dcef716d8f
commit 8ab677964d
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
2 changed files with 8 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import (
"io/fs" "io/fs"
"log" "log"
"math/big" "math/big"
"os"
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -172,6 +173,10 @@ func (c *Certs) internalCompile(m map[string]*tls.Certificate) error {
// try to read key file // try to read key file
keyData, err := fs.ReadFile(c.kDir, keyName) keyData, err := fs.ReadFile(c.kDir, keyName)
if err != nil { if err != nil {
// ignore the file if the certificate doesn't exist
if os.IsNotExist(err) {
continue
}
return fmt.Errorf("failed to read key file '%s': %w", keyName, err) return fmt.Errorf("failed to read key file '%s': %w", keyName, err)
} }

View File

@ -59,8 +59,8 @@ func (s *serveCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
return subcommands.ExitFailure return subcommands.ExitFailure
} }
var conf startUpConfig var config startUpConfig
err = json.NewDecoder(openConf).Decode(&conf) err = json.NewDecoder(openConf).Decode(&config)
if err != nil { if err != nil {
log.Println("[Violet] Error: invalid config file: ", err) log.Println("[Violet] Error: invalid config file: ", err)
return subcommands.ExitFailure return subcommands.ExitFailure
@ -68,7 +68,7 @@ func (s *serveCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{
// working directory is the parent of the config file // working directory is the parent of the config file
wd := filepath.Dir(s.configPath) wd := filepath.Dir(s.configPath)
normalLoad(conf, wd) normalLoad(config, wd)
return subcommands.ExitSuccess return subcommands.ExitSuccess
} }