spaceapid/util/config.go
Bendodroid 4b41acfa7b
Major Refactoring
- Move components to separate packages
- Fix HTTP header for 401 response
- Add documentation
2023-11-09 22:30:03 +01:00

49 lines
1.2 KiB
Go

package util
import (
"log"
"os"
"path/filepath"
"gitlab.hamburg.ccc.de/ccchh/spaceapid/config"
)
const (
envBAUsername = "BA_USERNAME"
envBAPassword = "BA_PASSWORD"
envJSONTemplatePath = "JSON_TEMPLATE_PATH"
)
// GetConfiguration gets the spaceapid configuration from the respective environment variables
func GetConfiguration() (c config.Configuration) {
var (
success bool
err error
)
// HTTP BasicAuth username
c.BAUsername, success = os.LookupEnv(envBAUsername)
if !success || c.BAUsername == "" {
log.Fatalln("Could not retrieve env variable", envBAUsername, "or variable is empty")
}
// HTTP BasicAuth password
c.BAPassword, success = os.LookupEnv(envBAPassword)
if !success || c.BAPassword == "" {
log.Fatalln("Could not retrieve", envBAPassword, "env variable or variable is empty")
}
// JSON template path
templatePath, success := os.LookupEnv(envJSONTemplatePath)
if !success || templatePath == "" {
log.Fatalln("Could not retrieve", envJSONTemplatePath, "env variable or variable is empty")
}
// Save as absolute path
c.TemplatePath, err = filepath.Abs(templatePath)
if err != nil {
log.Fatalln("Failed converting", templatePath, "to absolute path:", err)
}
return
}