Commit 2625e16f authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

config: fix typo GolbalConfig -> GlobalConfig

parent c404c7af
......@@ -30,10 +30,10 @@ import (
)
// Global configuration
var GolbalConfig *config.Config = nil
var GlobalConfig *config.Config = nil
func InitConfig() error {
if GolbalConfig != nil {
if GlobalConfig != nil {
return nil
}
......@@ -128,25 +128,25 @@ func InitConfig() error {
env := config.NewEnvironment(mappings)
if _, err := os.Stat(*configFile); os.IsNotExist(err) {
GolbalConfig = config.NewConfig([]config.Provider{defaults, env})
GlobalConfig = config.NewConfig([]config.Provider{defaults, env})
} else {
yamlFile := config.NewYAMLFile(*configFile)
GolbalConfig = config.NewConfig([]config.Provider{defaults, yamlFile, env})
GlobalConfig = config.NewConfig([]config.Provider{defaults, yamlFile, env})
}
err := GolbalConfig.Load()
err := GlobalConfig.Load()
if err != nil {
log.Fatal("failed to parse config")
return err
}
m, err := GolbalConfig.String("mode")
m, err := GlobalConfig.String("mode")
if err != nil {
return err
}
if m != "test" {
settings, _ := GolbalConfig.Settings()
settings, _ := GlobalConfig.Settings()
log.Print("All settings:")
for key, val := range settings {
// TODO password settings should be excluded!
......@@ -165,31 +165,31 @@ func ConfigureBackend() (string, string, string, string, string, string, string,
return "", "", "", "", "", "", "", err
}
mode, err := GolbalConfig.String("mode")
mode, err := GlobalConfig.String("mode")
if err != nil {
log.Printf("Error reading mode from global configuration: %v, aborting.", err.Error())
return "", "", "", "", "", "", "", err
}
baseHost, err := GolbalConfig.String("base.host")
baseHost, err := GlobalConfig.String("base.host")
if err != nil {
log.Printf("Error reading base.host from global configuration: %v, aborting.", err.Error())
return "", "", "", "", "", "", "", err
}
basePath, err := GolbalConfig.String("base.path")
basePath, err := GlobalConfig.String("base.path")
if err != nil {
log.Printf("Error reading base.path from global configuration: %v, aborting.", err.Error())
return "", "", "", "", "", "", "", err
}
port, err := GolbalConfig.String("port")
port, err := GlobalConfig.String("port")
if err != nil {
log.Printf("Error reading port from global configuration: %v, aborting.", err.Error())
return "", "", "", "", "", "", "", err
}
AMQPhost, _ := GolbalConfig.String("amqp.host")
AMQPuser, _ := GolbalConfig.String("amqp.user")
AMQPpass, _ := GolbalConfig.String("amqp.pass")
AMQPhost, _ := GlobalConfig.String("amqp.host")
AMQPuser, _ := GlobalConfig.String("amqp.user")
AMQPpass, _ := GlobalConfig.String("amqp.pass")
return mode, baseHost, basePath, port, AMQPhost, AMQPuser, AMQPpass, nil
}
......@@ -23,10 +23,11 @@ package database
import (
"fmt"
"github.com/zpatrick/go-config"
"os"
"testing"
"github.com/zpatrick/go-config"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
"github.com/stretchr/testify/assert"
)
......@@ -52,33 +53,33 @@ func TestInitDB(t *testing.T) {
err = InitDB(ownconfig)
assert.Error(t, err)
dbname, err := configuration.GolbalConfig.String("db.name")
dbname, err := configuration.GlobalConfig.String("db.name")
assert.NoError(t, err)
static["db.name"] = dbname
ownconfig = config.NewConfig([]config.Provider{defaults, env})
err = InitDB(ownconfig)
assert.Error(t, err)
dbhost, err := configuration.GolbalConfig.String("db.host")
dbhost, err := configuration.GlobalConfig.String("db.host")
assert.NoError(t, err)
static["db.host"] = dbhost
ownconfig = config.NewConfig([]config.Provider{defaults, env})
err = InitDB(ownconfig)
assert.Error(t, err)
dbuser, err := configuration.GolbalConfig.String("db.user")
dbuser, err := configuration.GlobalConfig.String("db.user")
static["db.user"] = dbuser
ownconfig = config.NewConfig([]config.Provider{defaults, env})
err = InitDB(ownconfig)
assert.Error(t, err)
dbpass, err := configuration.GolbalConfig.String("db.pass")
dbpass, err := configuration.GlobalConfig.String("db.pass")
static["db.pass"] = dbpass
ownconfig = config.NewConfig([]config.Provider{defaults, env})
err = InitDB(ownconfig)
assert.Error(t, err)
dbssl, err := configuration.GolbalConfig.String("db.ssl")
dbssl, err := configuration.GlobalConfig.String("db.ssl")
assert.NoError(t, err)
static["db.ssl"] = dbssl
ownconfig = config.NewConfig([]config.Provider{defaults, env})
......
......@@ -23,17 +23,18 @@ package component_configuration
import (
"fmt"
"os"
"testing"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
var router *gin.Engine
......@@ -146,7 +147,7 @@ func TestMain(m *testing.M) {
panic(m)
}
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
panic(m)
}
......
......@@ -23,6 +23,10 @@ package dashboard
import (
"fmt"
"log"
"os"
"testing"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
......@@ -31,9 +35,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/stretchr/testify/assert"
"log"
"os"
"testing"
)
var router *gin.Engine
......@@ -80,7 +81,7 @@ func TestMain(m *testing.M) {
if err != nil {
panic(m)
}
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
panic(m)
}
......
......@@ -98,7 +98,7 @@ func (f *File) Register(fileHeader *multipart.FileHeader, scenarioID uint) error
}
defer fileContent.Close()
bucket, err := configuration.GolbalConfig.String("s3.bucket")
bucket, err := configuration.GlobalConfig.String("s3.bucket")
if bucket == "" {
f.FileData, err = ioutil.ReadAll(fileContent)
f.Key = ""
......@@ -157,7 +157,7 @@ func (f *File) update(fileHeader *multipart.FileHeader) error {
}
defer fileContent.Close()
bucket, err := configuration.GolbalConfig.String("s3.bucket")
bucket, err := configuration.GlobalConfig.String("s3.bucket")
if bucket == "" {
f.FileData, err = ioutil.ReadAll(fileContent)
f.Key = ""
......
......@@ -40,7 +40,7 @@ var s3Session *session.Session = nil
func getS3Session() (*session.Session, string, error) {
bucket, err := configuration.GolbalConfig.String("s3.bucket")
bucket, err := configuration.GlobalConfig.String("s3.bucket")
if err != nil || bucket == "" {
return nil, "", fmt.Errorf("no S3 bucket configured: %s", err)
}
......@@ -57,10 +57,10 @@ func getS3Session() (*session.Session, string, error) {
}
func createS3Session() (*session.Session, error) {
endpoint, err := configuration.GolbalConfig.String("s3.endpoint")
region, err := configuration.GolbalConfig.String("s3.region")
pathStyle, err := configuration.GolbalConfig.Bool("s3.pathstyle")
nossl, err := configuration.GolbalConfig.Bool("s3.nossl")
endpoint, err := configuration.GlobalConfig.String("s3.endpoint")
region, err := configuration.GlobalConfig.String("s3.region")
pathStyle, err := configuration.GlobalConfig.Bool("s3.pathstyle")
nossl, err := configuration.GlobalConfig.Bool("s3.nossl")
sess, err := session.NewSession(
&aws.Config{
......
......@@ -24,6 +24,14 @@ package file
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/http/httptest"
"os"
"testing"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
......@@ -32,13 +40,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/http/httptest"
"os"
"testing"
)
var router *gin.Engine
......@@ -83,7 +84,7 @@ func TestMain(m *testing.M) {
if err != nil {
panic(m)
}
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
panic(m)
}
......
......@@ -22,14 +22,15 @@
package healthz
import (
"log"
"net/http"
"strings"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
"github.com/gin-gonic/gin"
"log"
"net/http"
"strings"
)
func RegisterHealthzEndpoint(r *gin.RouterGroup) {
......@@ -55,7 +56,7 @@ func getHealth(c *gin.Context) {
}
// check if connection to AMQP broker is alive if backend was started with AMQP client
url, err := configuration.GolbalConfig.String("amqp.host")
url, err := configuration.GlobalConfig.String("amqp.host")
if err != nil && strings.Contains(err.Error(), "Required setting 'amqp.host' not set") {
c.JSON(http.StatusOK, gin.H{})
return
......
......@@ -22,15 +22,16 @@
package healthz
import (
"log"
"net/http"
"testing"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"log"
"net/http"
"testing"
)
var router *gin.Engine
......@@ -40,7 +41,7 @@ func TestHealthz(t *testing.T) {
assert.NoError(t, err)
// connect DB
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
assert.NoError(t, err)
defer database.DBpool.Close()
......@@ -58,7 +59,7 @@ func TestHealthz(t *testing.T) {
assert.Equalf(t, 500, code, "Response body: \n%v\n", resp)
// reconnect DB
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
assert.NoError(t, err)
defer database.DBpool.Close()
......@@ -68,11 +69,11 @@ func TestHealthz(t *testing.T) {
assert.Equalf(t, 500, code, "Response body: \n%v\n", resp)
// connect AMQP client (make sure that AMQP_HOST, AMQP_USER, AMQP_PASS are set via command line parameters)
host, err := configuration.GolbalConfig.String("amqp.host")
host, err := configuration.GlobalConfig.String("amqp.host")
assert.NoError(t, err)
user, err := configuration.GolbalConfig.String("amqp.user")
user, err := configuration.GlobalConfig.String("amqp.user")
assert.NoError(t, err)
pass, err := configuration.GolbalConfig.String("amqp.pass")
pass, err := configuration.GlobalConfig.String("amqp.pass")
assert.NoError(t, err)
amqpURI := "amqp://" + user + ":" + pass + "@" + host
......
......@@ -24,15 +24,16 @@ package infrastructure_component
import (
"encoding/json"
"fmt"
"os"
"testing"
"time"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
component_configuration "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/streadway/amqp"
"github.com/stretchr/testify/assert"
"os"
"testing"
"time"
"github.com/gin-gonic/gin"
......@@ -94,7 +95,7 @@ func TestMain(m *testing.M) {
panic(m)
}
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
panic(m)
}
......@@ -126,9 +127,9 @@ func TestAddICAsAdmin(t *testing.T) {
// connect AMQP client
// Make sure that AMQP_HOST, AMQP_USER, AMQP_PASS are set
host, err := configuration.GolbalConfig.String("amqp.host")
user, err := configuration.GolbalConfig.String("amqp.user")
pass, err := configuration.GolbalConfig.String("amqp.pass")
host, err := configuration.GlobalConfig.String("amqp.host")
user, err := configuration.GlobalConfig.String("amqp.user")
pass, err := configuration.GlobalConfig.String("amqp.pass")
amqpURI := "amqp://" + user + ":" + pass + "@" + host
// AMQP Connection startup is tested here
......
......@@ -42,7 +42,7 @@ func TestMain(m *testing.M) {
panic(m)
}
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
panic(m)
}
......@@ -51,9 +51,9 @@ func TestMain(m *testing.M) {
router = gin.Default()
// connect AMQP client (make sure that AMQP_HOST, AMQP_USER, AMQP_PASS are set via command line parameters)
host, err := configuration.GolbalConfig.String("amqp.host")
user, err := configuration.GolbalConfig.String("amqp.user")
pass, err := configuration.GolbalConfig.String("amqp.pass")
host, err := configuration.GlobalConfig.String("amqp.host")
user, err := configuration.GlobalConfig.String("amqp.user")
pass, err := configuration.GlobalConfig.String("amqp.pass")
amqpURI := "amqp://" + user + ":" + pass + "@" + host
......@@ -76,6 +76,6 @@ func TestAddTestData(t *testing.T) {
panic(t)
}
resp, err := AddTestData(configuration.GolbalConfig, router)
resp, err := AddTestData(configuration.GlobalConfig, router)
assert.NoError(t, err, "Response body: %v", resp)
}
......@@ -26,6 +26,14 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/http/httptest"
"os"
"testing"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
......@@ -35,13 +43,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/stretchr/testify/assert"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/http/httptest"
"os"
"testing"
)
var router *gin.Engine
......@@ -98,7 +99,7 @@ func TestMain(m *testing.M) {
if err != nil {
panic(m)
}
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
panic(m)
}
......
......@@ -23,6 +23,9 @@ package scenario
import (
"fmt"
"os"
"testing"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
......@@ -30,8 +33,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
var router *gin.Engine
......@@ -56,7 +57,7 @@ func TestMain(m *testing.M) {
panic(m)
}
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
panic(m)
}
......
......@@ -23,18 +23,19 @@ package signal
import (
"fmt"
"os"
"testing"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
component_configuration "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration"
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
var router *gin.Engine
......@@ -141,7 +142,7 @@ func TestMain(m *testing.M) {
panic(m)
}
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
panic(m)
}
......
......@@ -88,7 +88,7 @@ func authenticate(c *gin.Context) {
return
}
expiresStr, err := configuration.GolbalConfig.String("jwt.expires-after")
expiresStr, err := configuration.GlobalConfig.String("jwt.expires-after")
if err != nil {
helper.UnauthorizedError(c, "Backend configuration error")
return
......@@ -100,7 +100,7 @@ func authenticate(c *gin.Context) {
return
}
secret, err := configuration.GolbalConfig.String("jwt.secret")
secret, err := configuration.GlobalConfig.String("jwt.secret")
if err != nil {
helper.UnauthorizedError(c, "Backend configuration error")
return
......
......@@ -68,7 +68,7 @@ func Authentication(unauthorized bool) gin.HandlerFunc {
}
// return secret in byte format
secret, _ := configuration.GolbalConfig.String("jwt.secret")
secret, _ := configuration.GlobalConfig.String("jwt.secret")
return []byte(secret), nil
})
......
......@@ -56,7 +56,7 @@ func TestMain(m *testing.M) {
panic(m)
}
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
panic(m)
}
......
......@@ -23,6 +23,9 @@ package widget
import (
"fmt"
"os"
"testing"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
......@@ -32,8 +35,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
var router *gin.Engine
......@@ -105,7 +106,7 @@ func TestMain(m *testing.M) {
panic(m)
}
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
panic(m)
}
......
......@@ -30,7 +30,7 @@ import (
apidocs "git.rwth-aachen.de/acs/public/villas/web-backend-go/doc/api" // doc/api folder is used by Swag CLI, you have to import it
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
"github.com/gin-gonic/gin"
"github.com/zpatrick/go-config"
)
......@@ -79,7 +79,7 @@ func main() {
}
//init database
err = database.InitDB(configuration.GolbalConfig)
err = database.InitDB(configuration.GlobalConfig)
if err != nil {
log.Printf("Error during initialization of database: %v, aborting.", err.Error())
panic(err)
......@@ -107,7 +107,7 @@ func main() {
}
// add data to DB (if any)
err = addData(r, configuration.GolbalConfig)