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
No related branches found
No related tags found
No related merge requests found
Pipeline #54556 passed
......@@ -12,7 +12,21 @@ import (
func Start() {
server := mqtt.New(nil)
_ = server.AddHook(new(auth.AllowHook), nil)
if os.Getenv("MQTT_USERNAME") == "" {
_ = 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") == "" {
log.Log.Fatal("please set MQTT_LISTEN")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment