From 30955b041cc8b4160f02cf8ff1b70eeb6496c50b Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 26 Apr 2018 12:09:46 +0200 Subject: [PATCH] Updated certificate loader --- security.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/security.go b/security.go index 7cc64438..c3d27014 100644 --- a/security.go +++ b/security.go @@ -2,29 +2,38 @@ package main import ( "os" + "path" "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/fatih/color" ) func configureHTTPS(app *aero.Application) { - fullCertPath := "security/fullchain.pem" - fullKeyPath := "security/privkey.pem" + fullCertPath := path.Join(arn.Root, "security", "fullchain.pem") + fullKeyPath := path.Join(arn.Root, "security", "privkey.pem") 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) 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) { - defaultKeyPath := "security/default/privkey.pem" + defaultKeyPath := path.Join(arn.Root, "security", "default", "privkey.pem") err := os.Link(defaultKeyPath, fullKeyPath) 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()) } }