From 745e7d665819b1b859b6178df3807b67d7c889bb Mon Sep 17 00:00:00 2001 From: leandrofars Date: Tue, 12 Mar 2024 12:06:31 -0300 Subject: [PATCH] fix(mqtt): ignored folders --- backend/services/mtp/mqtt/.gitignore | 4 +- backend/services/mtp/mqtt/cmd/mqtt/auth.json | 54 ++++++++++++++++++++ backend/services/mtp/mqtt/cmd/mqtt/main.go | 35 +++++++++++++ backend/services/mtp/mqtt/cmd/mqtt/run.sh | 1 + 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 backend/services/mtp/mqtt/cmd/mqtt/auth.json create mode 100644 backend/services/mtp/mqtt/cmd/mqtt/main.go create mode 100644 backend/services/mtp/mqtt/cmd/mqtt/run.sh diff --git a/backend/services/mtp/mqtt/.gitignore b/backend/services/mtp/mqtt/.gitignore index d07460d..cadd04c 100644 --- a/backend/services/mtp/mqtt/.gitignore +++ b/backend/services/mtp/mqtt/.gitignore @@ -1,4 +1,3 @@ -cmd/mqtt .DS_Store *.db auth.prod.json @@ -7,4 +6,5 @@ mochi *.pem *.crt *.key -*.local \ No newline at end of file +*.local +./mqtt \ No newline at end of file diff --git a/backend/services/mtp/mqtt/cmd/mqtt/auth.json b/backend/services/mtp/mqtt/cmd/mqtt/auth.json new file mode 100644 index 0000000..f05253a --- /dev/null +++ b/backend/services/mtp/mqtt/cmd/mqtt/auth.json @@ -0,0 +1,54 @@ +{ + "auth": [ + { + "username": "leandro", + "password": "leandro", + "allow": true + }, + { + "username": "steve", + "password": "steve", + "allow": true + }, + { + "username": "root", + "password": "root", + "allow": true + }, + { + "remote": "*", + "allow": false + }, + { + "remote": "*", + "allow": false + } + ], + "acl": [ + { + "remote": "*" + }, + { + "username": "leandro", + "filters": { + "oktopus/+/agent/+": 1, + "oktopus/+/controller/+": 2, + "oktopus/+/get/+": 2 + } + }, + { + "username": "steve", + "filters": { + "oktopus/+/agent/+": 1, + "oktopus/+/controller/+": 2, + "oktopus/+/get/+": 2 + } + }, + { + "username": "root", + "filters": { + "#": 3 + } + } + ] +} \ No newline at end of file diff --git a/backend/services/mtp/mqtt/cmd/mqtt/main.go b/backend/services/mtp/mqtt/cmd/mqtt/main.go new file mode 100644 index 0000000..b833a1e --- /dev/null +++ b/backend/services/mtp/mqtt/cmd/mqtt/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "broker/internal/config" + "broker/internal/listeners" + "log" + "os" + "os/signal" + "syscall" +) + +func main() { + + done := make(chan os.Signal, 1) + + conf := config.NewConfig() + + signal.Notify(done, syscall.SIGINT, syscall.SIGTERM) + + go listeners.StartServers(conf) + + if conf.WsEnable { + log.Printf("websocket is running at port %s", conf.WsPort) + } + + if conf.HttpEnable { + log.Printf("http is running at port %s", conf.HttpPort) + } + + log.Printf("mqtt is running at port %s", conf.MqttPort) + + <-done + + log.Println("server is shutting down...") +} diff --git a/backend/services/mtp/mqtt/cmd/mqtt/run.sh b/backend/services/mtp/mqtt/cmd/mqtt/run.sh new file mode 100644 index 0000000..186907d --- /dev/null +++ b/backend/services/mtp/mqtt/cmd/mqtt/run.sh @@ -0,0 +1 @@ +go run . -path auth.json