43 lines
1.2 KiB
Go
Raw Normal View History

2017-11-08 09:53:27 +00:00
package main
import (
"os"
2018-04-26 10:09:46 +00:00
"path"
2017-11-08 09:53:27 +00:00
"github.com/aerogo/aero"
2019-04-23 05:45:17 +00:00
"github.com/akyoto/color"
2019-04-23 05:52:55 +00:00
"github.com/animenotifier/arn"
2017-11-08 09:53:27 +00:00
)
func configureHTTPS(app *aero.Application) {
2018-04-26 10:09:46 +00:00
fullCertPath := path.Join(arn.Root, "security", "fullchain.pem")
fullKeyPath := path.Join(arn.Root, "security", "privkey.pem")
2017-11-08 09:53:27 +00:00
if _, err := os.Stat(fullCertPath); os.IsNotExist(err) {
2018-06-23 05:23:53 +00:00
defaultCertPath := path.Join(arn.Root, "security", "default", "server.crt")
2017-11-08 09:53:27 +00:00
err := os.Link(defaultCertPath, fullCertPath)
if err != nil {
2018-04-26 10:09:46 +00:00
// 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())
2017-11-08 09:53:27 +00:00
}
}
if _, err := os.Stat(fullKeyPath); os.IsNotExist(err) {
2018-06-23 05:23:53 +00:00
defaultKeyPath := path.Join(arn.Root, "security", "default", "server.key")
2017-11-08 09:53:27 +00:00
err := os.Link(defaultKeyPath, fullKeyPath)
if err != nil {
2018-04-26 10:09:46 +00:00
// 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())
2017-11-08 09:53:27 +00:00
}
}
// HTTPS
app.Security.Load(fullCertPath, fullKeyPath)
}