Commit 4945d6ee authored by Sonja Happ's avatar Sonja Happ
Browse files

use separate ENV variables for AMQP username and password

parent 4a58143a
......@@ -43,7 +43,9 @@ func InitConfig() error {
dbUser = flag.String("dbuser", "", "Username of database connection (default is <empty>)")
dbPass = flag.String("dbpass", "", "Password of database connection (default is <empty>)")
dbSSLMode = flag.String("dbsslmode", "disable", "SSL mode of DB (default is disable)") // TODO: change default for production
amqpURL = flag.String("amqp", "", "If set, use this url to connect to an AMQP broker (default is disabled)")
amqpHost = flag.String("amqphost", "", "If set, use this as host for AMQP broker (default is disabled)")
amqpUser = flag.String("amqpuser", "", "Username for AMQP broker")
amqpPass = flag.String("amqppass", "", "Password for AMQP broker")
configFile = flag.String("configFile", "", "Path to YAML configuration file")
mode = flag.String("mode", "release", "Select debug/release/test mode (default is release)")
port = flag.String("port", "4000", "Port of the backend (default is 4000)")
......@@ -58,7 +60,9 @@ func InitConfig() error {
"db.user": *dbUser,
"db.pass": *dbPass,
"db.ssl": *dbSSLMode,
"amqp.url": *amqpURL,
"amqp.host": *amqpHost,
"amqp.user": *amqpUser,
"amqp.pass": *amqpPass,
"mode": *mode,
"port": *port,
"base.host": *baseHost,
......@@ -71,7 +75,9 @@ func InitConfig() error {
"DB_USER": "db.user",
"DB_PASS": "db.pass",
"DB_SSLMODE": "db.ssl",
"AMQP_URL": "amqp.url",
"AMQP_HOST": "amqp.host",
"AMQP_USER": "amqp.user",
"AMQP_PASS": "amqp.pass",
"BASE_HOST": "base.host",
"BASE_PATH": "base.path",
"MODE": "mode",
......
......@@ -45,24 +45,24 @@ import (
"github.com/gin-gonic/gin"
)
func configureBackend() (string, string, string, string, string, error) {
func configureBackend() (string, string, string, string, string, string, string, error) {
err := configuration.InitConfig()
if err != nil {
log.Printf("Error during initialization of global configuration: %v, aborting.", err.Error())
return "", "", "", "", "", err
return "", "", "", "", "", "", "", err
}
err = database.InitDB(configuration.GolbalConfig)
if err != nil {
log.Printf("Error during initialization of database: %v, aborting.", err.Error())
return "", "", "", "", "", err
return "", "", "", "", "", "", "", err
}
mode, err := configuration.GolbalConfig.String("mode")
if err != nil {
log.Printf("Error reading mode from global configuration: %v, aborting.", err.Error())
return "", "", "", "", "", err
return "", "", "", "", "", "", "", err
}
if mode == "release" {
......@@ -72,17 +72,17 @@ func configureBackend() (string, string, string, string, string, error) {
baseHost, err := configuration.GolbalConfig.String("base.host")
if err != nil {
log.Printf("Error reading base.host from global configuration: %v, aborting.", err.Error())
return "", "", "", "", "", err
return "", "", "", "", "", "", "", err
}
basePath, err := configuration.GolbalConfig.String("base.path")
if err != nil {
log.Printf("Error reading base.path from global configuration: %v, aborting.", err.Error())
return "", "", "", "", "", err
return "", "", "", "", "", "", "", err
}
port, err := configuration.GolbalConfig.String("port")
if err != nil {
log.Printf("Error reading port from global configuration: %v, aborting.", err.Error())
return "", "", "", "", "", err
return "", "", "", "", "", "", "", err
}
apidocs.SwaggerInfo.Host = baseHost
......@@ -90,9 +90,11 @@ func configureBackend() (string, string, string, string, string, error) {
metrics.InitCounters()
AMQPurl, _ := configuration.GolbalConfig.String("amqp.url")
AMQPhost, _ := configuration.GolbalConfig.String("amqp.host")
AMQPuser, _ := configuration.GolbalConfig.String("amqp.user")
AMQPpass, _ := configuration.GolbalConfig.String("amqp.pass")
return mode, baseHost, basePath, port, AMQPurl, nil
return mode, baseHost, basePath, port, AMQPhost, AMQPuser, AMQPpass, nil
}
......@@ -191,7 +193,7 @@ func connectAMQP(AMQPurl string, api *gin.RouterGroup) error {
func main() {
log.Println("Starting VILLASweb-backend-go")
mode, _, basePath, port, amqpurl, err := configureBackend()
mode, _, basePath, port, amqphost, amqpuser, amqppass, err := configureBackend()
if err != nil {
panic(err)
}
......@@ -206,6 +208,8 @@ func main() {
panic(err)
}
// create amqp URL based on username, password and host
amqpurl := amqpuser + ":" + amqppass + "@" + amqphost
err = connectAMQP(amqpurl, api)
if err != nil {
panic(err)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment