notify ui about identity changes

This commit is contained in:
Mary Lincy Dcouto
2021-03-08 18:33:15 +05:30
parent 343a52e7c4
commit d1766726bb
4 changed files with 38 additions and 7 deletions
+1
View File
@@ -517,6 +517,7 @@ namespace ZitiDesktopEdge {
found.Name = zid.Name;
found.ControllerUrl = zid.ControllerUrl;
found.IsEnabled = zid.IsEnabled;
LoadIdentities(true);
return;
}
} else {
+6 -2
View File
@@ -34,8 +34,12 @@ var SET_LOGLEVEL = dto.CommandMsg{
Function: "SetLogLevel",
}
var NOTIFY_UI = dto.CommandMsg{
Function: "NotifyUIAndUpdateService",
var NOTIFY_LOGLEVEL_UI_MONITOR = dto.CommandMsg{
Function: "NotifyLogLevelUIAndUpdateService",
}
var NOTIFY_IDENTITY_UI = dto.CommandMsg{
Function: "NotifyIdentityUI",
}
var templateIdentity = `{{printf "%40s" "Name"}} | {{printf "%41s" "FingerPrint"}} | {{printf "%6s" "Active"}} | {{printf "%30s" "Config"}} | {{"Status"}}
+9 -4
View File
@@ -19,7 +19,12 @@ func OnOffIdentity(args []string, flags map[string]bool) {
identityPayload["Fingerprint"] = args[0]
ONOFF_IDENTITY.Payload = identityPayload
log.Debugf("OnOffIdentity Payload %v", ONOFF_IDENTITY)
GetDataFromIpcPipe(&ONOFF_IDENTITY, nil, GetIdentityResponseObjectFromRTS, args, flags)
status := GetDataFromIpcPipe(&ONOFF_IDENTITY, nil, GetIdentityResponseObjectFromRTS, args, flags)
if status {
NOTIFY_IDENTITY_UI.Payload = identityPayload
log.Infof("Notifying the Identity Status to UI %v", identityPayload)
GetDataFromIpcPipe(&NOTIFY_IDENTITY_UI, nil, GetResponseObjectFromRTS, args, flags)
}
}
//SetLogLevel is to change the loglevel through cmdline
@@ -33,9 +38,9 @@ func SetLogLevel(args []string, flags map[string]bool) {
log.Debugf("LogLevel Payload %v", SET_LOGLEVEL)
status := GetDataFromIpcPipe(&SET_LOGLEVEL, nil, GetResponseObjectFromRTS, args, flags)
if status {
NOTIFY_UI.Payload = loglevelPayload
log.Infof("Notifying the LogLevel to UI and Ziti monitor service %v", NOTIFY_UI)
GetDataFromIpcPipe(&NOTIFY_UI, nil, GetResponseObjectFromRTS, args, flags)
NOTIFY_LOGLEVEL_UI_MONITOR.Payload = loglevelPayload
log.Infof("Notifying the LogLevel to UI and Ziti monitor service %v", loglevelPayload)
GetDataFromIpcPipe(&NOTIFY_LOGLEVEL_UI_MONITOR, nil, GetResponseObjectFromRTS, args, flags)
}
}
}
+22 -1
View File
@@ -433,8 +433,10 @@ func serveIpc(conn net.Conn) {
toggleIdentity(enc, fingerprint, onOff)
case "SetLogLevel":
setLogLevel(enc, cmd.Payload["Level"].(string))
case "NotifyUIAndUpdateService":
case "NotifyLogLevelUIAndUpdateService":
sendLogLevelAndNotify(enc, cmd.Payload["Level"].(string))
case "NotifyIdentityUI":
sendIdentityAndNotifyUI(enc, cmd.Payload["Fingerprint"].(string))
case "ZitiDump":
log.Debug("request to ZitiDump received")
for _, id := range rts.ids {
@@ -1007,6 +1009,25 @@ func sendLogLevelAndNotify(enc *json.Encoder, loglevel string) {
LogLevel: loglevel,
}
message := fmt.Sprintf("Loglevel %s is sent to the events channel", loglevel)
log.Info(message)
resp := dto.Response{Message: "success", Code: SUCCESS, Error: "", Payload: message}
respond(enc, resp)
}
func sendIdentityAndNotifyUI(enc *json.Encoder, fingerprint string) {
for _, id := range rts.ids {
if id.FingerPrint == fingerprint {
events.broadcast <- dto.IdentityEvent{
ActionEvent: IDENTITY_ADDED,
Id: id.Identity,
}
message := fmt.Sprintf("Identity %s - %s updated message is sent to the events channel", id.Identity.Name, id.Identity.FingerPrint)
log.Info(message)
resp := dto.Response{Message: "success", Code: SUCCESS, Error: "", Payload: message}
respond(enc, resp)
return
}
}
resp := dto.Response{Message: "", Code: ERROR, Error: "Could not find id matching fingerprint " + fingerprint, Payload: ""}
respond(enc, resp)
}