Updated certificate loader

This commit is contained in:
Eduard Urbach 2018-04-26 12:09:46 +02:00
parent 54bfdebcf5
commit 30955b041c

View File

@ -2,29 +2,38 @@ package main
import ( import (
"os" "os"
"path"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/fatih/color"
) )
func configureHTTPS(app *aero.Application) { func configureHTTPS(app *aero.Application) {
fullCertPath := "security/fullchain.pem" fullCertPath := path.Join(arn.Root, "security", "fullchain.pem")
fullKeyPath := "security/privkey.pem" fullKeyPath := path.Join(arn.Root, "security", "privkey.pem")
if _, err := os.Stat(fullCertPath); os.IsNotExist(err) { if _, err := os.Stat(fullCertPath); os.IsNotExist(err) {
defaultCertPath := "security/default/fullchain.pem" defaultCertPath := path.Join(arn.Root, "security", "default", "fullchain.pem")
err := os.Link(defaultCertPath, fullCertPath) err := os.Link(defaultCertPath, fullCertPath)
if err != nil { if err != nil {
panic(err) // Do not panic here, multiple tests could be running this in parallel.
// Therefore, races can occur (which test writes the link first).
// Simply log the error and continue as the file should be present.
color.Red(err.Error())
} }
} }
if _, err := os.Stat(fullKeyPath); os.IsNotExist(err) { if _, err := os.Stat(fullKeyPath); os.IsNotExist(err) {
defaultKeyPath := "security/default/privkey.pem" defaultKeyPath := path.Join(arn.Root, "security", "default", "privkey.pem")
err := os.Link(defaultKeyPath, fullKeyPath) err := os.Link(defaultKeyPath, fullKeyPath)
if err != nil { if err != nil {
panic(err) // Do not panic here, multiple tests could be running this in parallel.
// Therefore, races can occur (which test writes the link first).
// Simply log the error and continue as the file should be present.
color.Red(err.Error())
} }
} }