Skip to content
Snippets Groups Projects
Commit 547b4033 authored by Jonas Leder's avatar Jonas Leder
Browse files

implement authentication for embedded MQTT server

parent 6b6d1768
Branches
No related tags found
No related merge requests found
Pipeline #54556 passed
...@@ -12,7 +12,21 @@ import ( ...@@ -12,7 +12,21 @@ import (
func Start() { func Start() {
server := mqtt.New(nil) server := mqtt.New(nil)
if os.Getenv("MQTT_USERNAME") == "" {
_ = server.AddHook(new(auth.AllowHook), nil) _ = server.AddHook(new(auth.AllowHook), nil)
} else {
_ = server.AddHook(new(auth.Hook), &auth.Options{
Ledger: &auth.Ledger{
Auth: auth.AuthRules{
{
Username: auth.RString(os.Getenv("MQTT_USERNAME")),
Password: auth.RString(os.Getenv("MQTT_PASSWORD")),
Allow: true,
},
},
},
})
}
if os.Getenv("MQTT_LISTEN") == "" { if os.Getenv("MQTT_LISTEN") == "" {
log.Log.Fatal("please set MQTT_LISTEN") log.Log.Fatal("please set MQTT_LISTEN")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment