From 8ab677964dd3fac0066dcf6f7fbf02e34c84ee07 Mon Sep 17 00:00:00 2001 From: MrMelon54 Date: Sun, 16 Jul 2023 21:17:15 +0100 Subject: [PATCH] Fix certificates not loading when key file exists --- certs/certs.go | 5 +++++ cmd/violet/serve.go | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/certs/certs.go b/certs/certs.go index 56921b0..016b301 100644 --- a/certs/certs.go +++ b/certs/certs.go @@ -10,6 +10,7 @@ import ( "io/fs" "log" "math/big" + "os" "strings" "sync" "sync/atomic" @@ -172,6 +173,10 @@ func (c *Certs) internalCompile(m map[string]*tls.Certificate) error { // try to read key file keyData, err := fs.ReadFile(c.kDir, keyName) 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) } diff --git a/cmd/violet/serve.go b/cmd/violet/serve.go index 48e7faa..1978874 100644 --- a/cmd/violet/serve.go +++ b/cmd/violet/serve.go @@ -59,8 +59,8 @@ func (s *serveCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{ return subcommands.ExitFailure } - var conf startUpConfig - err = json.NewDecoder(openConf).Decode(&conf) + var config startUpConfig + err = json.NewDecoder(openConf).Decode(&config) if err != nil { log.Println("[Violet] Error: invalid config file: ", err) 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 wd := filepath.Dir(s.configPath) - normalLoad(conf, wd) + normalLoad(config, wd) return subcommands.ExitSuccess }