database configuration only via PG* env variables and MQTT password only via configured env var
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2023-12-17 13:53:16 +01:00
parent 6d932f56c8
commit ee2c5f31e8
11 changed files with 59 additions and 38 deletions

View File

@ -0,0 +1,23 @@
{
"mqtt": {
"broker": "ssl://eu1.cloud.thethings.network:8883",
"username": "de-hottis-level-monitoring@ttn",
"password": "ENV",
"tlsEnable": "true"
},
"topicMappings": [
{
"topics": [ "v3/#" ],
"handler": "TTN",
"id": "TTN0",
"config": {
"databaseConnStr": "",
"attributes": {
}
}
}
],
"archiver": {
"dir": "/archive"
}
}

View File

@ -0,0 +1,23 @@
{
"mqtt": {
"broker": "ssl://eu1.cloud.thethings.network:8883",
"username": "de-hottis-level-monitoring@ttn",
"password": "ENV",
"tlsEnable": "true"
},
"topicMappings": [
{
"topics": [ "v3/#" ],
"handler": "TTN",
"id": "TTN0",
"config": {
"databaseConnStr": "",
"attributes": {
}
}
}
],
"archiver": {
"dir": "./tmp/udi"
}
}

View File

@ -2,7 +2,7 @@
"mqtt": {
"broker": "ssl://eu1.cloud.thethings.network:8883",
"username": "de-hottis-level-monitoring@ttn",
"password": "ENV",
"passwordEnvVar": "MQTT_PASSWORD",
"tlsEnable": "true"
},
"topicMappings": [

View File

@ -5,7 +5,6 @@ import "log"
import "os"
type HandlerConfigT struct {
DatabaseConnStr string `json:"databaseConnStr"`
Attributes map[string]string `json:"attributes"`
}
@ -13,7 +12,8 @@ type ConfigT struct {
Mqtt struct {
Broker string `json:"broker"`
Username string `json:"username"`
Password string `json:"password"`
PasswordEnvVar string `json:"passwordEnvVar"`
Password string
TlsEnable string `json:"tlsEnable"`
} `json:"mqtt"`
TopicMappings []struct {
@ -36,8 +36,8 @@ func LoadConfiguration() {
log.Fatalf("Unable to parse configuration: %s", err)
}
if Config.Mqtt.Password == "ENV" {
Config.Mqtt.Password = os.Getenv("MQTT_PASSWORD")
if Config.Mqtt.PasswordEnvVar != "" {
Config.Mqtt.Password = os.Getenv(Config.Mqtt.PasswordEnvVar)
}
}

View File

@ -1,26 +0,0 @@
{
"mqtt": {
"broker": "172.23.1.102:1883",
"username": "",
"password": "",
"tlsEnable": "false"
},
"topicMappings": [
{
"topics": ["IoT/MBGW3/Measurement"],
"handler": "IoT"
}
],
"handlers": [
{
"name": "IoT",
"databaseConnStr": "",
"attributes": {
}
}
],
"archiver": {
"dir": "/mnt/udi/archive"
}
}

View File

@ -14,9 +14,10 @@ type DatabaseHandle struct {
dbh *gorm.DB
}
func NewDatabaseHandle(dsn string) *DatabaseHandle {
func NewDatabaseHandle() *DatabaseHandle {
var db DatabaseHandle
conn, err := gorm.Open(postgres.Open(dsn))
// inject the whole database configuration via the well-known PG* env variables
conn, err := gorm.Open(postgres.Open(""))
if err != nil {
log.Printf("Unable to open database connection: %s", err)
db.initialized = false

View File

@ -36,7 +36,7 @@ func NewMbgw3Handler(config config.HandlerConfigT) handler.Handler {
id: idSeq,
}
idSeq += 1
t.dbh = database.NewDatabaseHandle(config.DatabaseConnStr)
t.dbh = database.NewDatabaseHandle()
return t
}

View File

@ -45,7 +45,7 @@ func NewPvHandler(config config.HandlerConfigT) handler.Handler {
id: idSeq,
}
idSeq += 1
t.dbh = database.NewDatabaseHandle(config.DatabaseConnStr)
t.dbh = database.NewDatabaseHandle()
return t
}

View File

@ -78,7 +78,7 @@ func NewSvejHandler(config config.HandlerConfigT) handler.Handler {
}
t.ready = true
t.dbh = database.NewDatabaseHandle(config.DatabaseConnStr)
t.dbh = database.NewDatabaseHandle()
return t
}

View File

@ -129,7 +129,7 @@ func NewSverHandler(config config.HandlerConfigT) handler.Handler {
t.config = localConfig
t.ready = true
t.dbh = database.NewDatabaseHandle(config.DatabaseConnStr)
t.dbh = database.NewDatabaseHandle()
return t
}

View File

@ -81,7 +81,7 @@ func NewTTNHandler(config config.HandlerConfigT) handler.Handler {
id: idSeq,
}
idSeq += 1
t.dbh = database.NewDatabaseHandle(config.DatabaseConnStr)
t.dbh = database.NewDatabaseHandle()
return t
}