mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 00:43:58 +08:00
create emqx credentials for host upon creation
This commit is contained in:
@@ -564,6 +564,13 @@ func createNode(w http.ResponseWriter, r *http.Request) {
|
|||||||
data.Node.Server = servercfg.GetServer()
|
data.Node.Server = servercfg.GetServer()
|
||||||
if !logic.HostExists(&data.Host) {
|
if !logic.HostExists(&data.Host) {
|
||||||
logic.CheckHostPorts(&data.Host)
|
logic.CheckHostPorts(&data.Host)
|
||||||
|
if servercfg.GetBrokerType() == servercfg.EmqxBrokerType {
|
||||||
|
// create EMQX credentials for host if it doesn't exists
|
||||||
|
if err := mq.CreateEmqxUser(data.Host.ID.String(), data.Host.HostPass, false); err != nil {
|
||||||
|
logger.Log(0, "failed to add host credentials to EMQX: ", data.Host.ID.String(), err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err := logic.CreateHost(&data.Host); err != nil {
|
if err := logic.CreateHost(&data.Host); err != nil {
|
||||||
if errors.Is(err, logic.ErrHostExists) {
|
if errors.Is(err, logic.ErrHostExists) {
|
||||||
@@ -589,7 +596,6 @@ func createNode(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = logic.AssociateNodeToHost(&data.Node, &data.Host)
|
err = logic.AssociateNodeToHost(&data.Node, &data.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Log(0, r.Header.Get("user"),
|
logger.Log(0, r.Header.Get("user"),
|
||||||
|
@@ -145,15 +145,6 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
|
|||||||
var sendPeerUpdate bool
|
var sendPeerUpdate bool
|
||||||
switch hostUpdate.Action {
|
switch hostUpdate.Action {
|
||||||
case models.UpdateHost:
|
case models.UpdateHost:
|
||||||
if servercfg.GetBrokerType() == servercfg.EmqxBrokerType {
|
|
||||||
// create EMQX credentials for host if it doesn't exists
|
|
||||||
if _, err := logic.GetHost(currentHost.ID.String()); err != nil {
|
|
||||||
if err := CreateEmqxUser(currentHost.ID.String(), currentHost.HostPass, false); err != nil {
|
|
||||||
logger.Log(0, "failed to add host credentials to EMQX: ", currentHost.ID.String(), err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
|
sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
|
||||||
err := logic.UpsertHost(currentHost)
|
err := logic.UpsertHost(currentHost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user