update mq topics to use servername

This commit is contained in:
Anish Mukherjee 2023-03-21 17:55:51 +05:30
parent 949438d5b5
commit 852abcf4e7
2 changed files with 12 additions and 6 deletions

View file

@ -292,7 +292,7 @@ func CreateHostACL(hostID, serverName string) error {
Action: "all", Action: "all",
}, },
{ {
Topic: fmt.Sprintf("host/serverupdate/%s", hostID), Topic: fmt.Sprintf("host/serverupdate/%s/%s", serverName, hostID),
Permission: "allow", Permission: "allow",
Action: "all", Action: "all",
}, },
@ -327,7 +327,7 @@ func CreateHostACL(hostID, serverName string) error {
var nodeAclMux sync.Mutex var nodeAclMux sync.Mutex
// AppendNodeUpdateACL - adds ACL rule for subscribing to node updates for a node ID // AppendNodeUpdateACL - adds ACL rule for subscribing to node updates for a node ID
func AppendNodeUpdateACL(hostID, nodeNetwork, nodeID string) error { func AppendNodeUpdateACL(hostID, nodeNetwork, nodeID, serverName string) error {
nodeAclMux.Lock() nodeAclMux.Lock()
defer nodeAclMux.Unlock() defer nodeAclMux.Unlock()
token, err := getEmqxAuthToken() token, err := getEmqxAuthToken()
@ -345,22 +345,22 @@ func AppendNodeUpdateACL(hostID, nodeNetwork, nodeID string) error {
Action: "subscribe", Action: "subscribe",
}, },
{ {
Topic: fmt.Sprintf("ping/%s", nodeID), Topic: fmt.Sprintf("ping/%s/%s", serverName, nodeID),
Permission: "allow", Permission: "allow",
Action: "all", Action: "all",
}, },
{ {
Topic: fmt.Sprintf("update/%s", nodeID), Topic: fmt.Sprintf("update/%s/%s", serverName, nodeID),
Permission: "allow", Permission: "allow",
Action: "all", Action: "all",
}, },
{ {
Topic: fmt.Sprintf("signal/%s", nodeID), Topic: fmt.Sprintf("signal/%s/%s", serverName, nodeID),
Permission: "allow", Permission: "allow",
Action: "all", Action: "all",
}, },
{ {
Topic: fmt.Sprintf("metrics/%s", nodeID), Topic: fmt.Sprintf("metrics/%s/%s", serverName, nodeID),
Permission: "allow", Permission: "allow",
Action: "all", Action: "all",
}, },

View file

@ -186,6 +186,12 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
logger.Log(0, "failed to send new node to host", hostUpdate.Host.Name, currentHost.ID.String(), err.Error()) logger.Log(0, "failed to send new node to host", hostUpdate.Host.Name, currentHost.ID.String(), err.Error())
return return
} else { } else {
if servercfg.GetBrokerType() == servercfg.EmqxBrokerType {
if err = AppendNodeUpdateACL(hu.Host.ID.String(), hu.Node.Network, hu.Node.ID.String(), servercfg.GetServer()); err != nil {
logger.Log(0, "failed to add ACLs for EMQX node", err.Error())
return
}
}
if err = PublishSingleHostPeerUpdate(context.Background(), currentHost, nil, nil); err != nil { if err = PublishSingleHostPeerUpdate(context.Background(), currentHost, nil, nil); err != nil {
logger.Log(0, "failed peers publish after join acknowledged", hostUpdate.Host.Name, currentHost.ID.String(), err.Error()) logger.Log(0, "failed peers publish after join acknowledged", hostUpdate.Host.Name, currentHost.ID.String(), err.Error())
return return