From 037e98333a013f080b9acac027b16e77b3313fc6 Mon Sep 17 00:00:00 2001 From: SudhanshuBawane Date: Thu, 7 Mar 2024 00:59:29 +0530 Subject: [PATCH] testing Signed-off-by: SudhanshuBawane --- backend/agentd/agentd.go | 2 +- backend/agentd/session.go | 38 ++++++++++++++++++++------------------ backend/agentd/watcher.go | 6 +++--- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/backend/agentd/agentd.go b/backend/agentd/agentd.go index 4b2abc073..b47f29cc2 100644 --- a/backend/agentd/agentd.go +++ b/backend/agentd/agentd.go @@ -326,7 +326,7 @@ func (a *Agentd) handleUserEvent(event store.WatchEventUserConfig) error { return errors.New("nil entry received from the user config watcher") } topic := messaging.UserConfigTopic(event.User.GetMetadata().Namespace, event.User.Username) - if err := a.bus.Publish(topic, event.User.Username); err != nil { + if err := a.bus.Publish(topic, &event); err != nil { logger.WithField("topic", topic).WithError(err). Error("unable to publish a user config update to the bus") return err diff --git a/backend/agentd/session.go b/backend/agentd/session.go index e19002a03..285ddee33 100644 --- a/backend/agentd/session.go +++ b/backend/agentd/session.go @@ -381,7 +381,6 @@ func (s *Session) sender() { // msg = transport.NewMessage(user.Username, configUser) case u := <-s.userConfig.updatesChannel: - watchEvent, ok := u.(*store.WatchEventUserConfig) fmt.Println("========== usrConfig Updates ========", watchEvent) if !ok { @@ -392,25 +391,28 @@ func (s *Session) sender() { //if watchEvent.User.Disabled && watchEvent.User.Username == s.user { // return //} - if watchEvent.Disabled { - fmt.Println("========= the user is now disabled =======") - s.stop() - return - } - - fmt.Println("========== usrConfig Updates ========", watchEvent) - //// Handle the delete/disable event - //switch userConfig { - //case store.WatchDelete: - // fmt.Println(" ======= delete =======", store.WatchDelete) + //if watchEvent.Disabled { + // fmt.Println("========= the user is now disabled =======") + // s.stop() // return - //case store.WatchCreate: - // fmt.Println("======= create user ====", store.WatchCreate) - //case store.WatchUpdate: - // fmt.Println("==== user update ======", store.WatchUpdate) - //default: - // panic("unhandled default case") //} + fmt.Println("========== usrConfig Updates ========", watchEvent) + // Handle the delete/disable event + switch watchEvent.Action { + case store.WatchDelete: + fmt.Println(" ======= delete =======", store.WatchDelete) + return + case store.WatchCreate: + fmt.Println("======= create user ====", store.WatchCreate) + case store.WatchUpdate: + if watchEvent.Disabled { + fmt.Println("========= the user is now disabled =======") + return + } + fmt.Println("==== user update ======", store.WatchUpdate) + default: + panic("unhandled default case") + } if watchEvent.User == nil { logger.Error("session received nil user in watch event") diff --git a/backend/agentd/watcher.go b/backend/agentd/watcher.go index 0d05d92b7..42940ef3f 100644 --- a/backend/agentd/watcher.go +++ b/backend/agentd/watcher.go @@ -138,7 +138,7 @@ func GetEntityConfigWatcher(ctx context.Context, client *clientv3.Client) <-chan // GetUserConfigWatcher watches changes to the UserConfig in etcd and publish them -- git#2806 // over the bus as store.WatchEventUserConfig func GetUserConfigWatcher(ctx context.Context, client *clientv3.Client) <-chan store.WatchEventUserConfig { - var userConfig corev2.User + key := etcdstorev2.StoreKey(storev2.ResourceRequest{ Context: ctx, StoreName: new(corev2.User).StoreName(), @@ -161,12 +161,12 @@ func GetUserConfigWatcher(ctx context.Context, client *clientv3.Client) <-chan s } // unmarshal the user config - + var userConfig corev2.User if err := proto.Unmarshal(response.Object, &userConfig); err != nil { continue } if userConfig.Disabled { - fmt.Println("======= user watch event in watcher ========", userConfig, string(rune(response.Type))) + fmt.Println("======= user watch event in watcher ========", userConfig.Username, userConfig.Disabled, response.Type) } ch <- store.WatchEventUserConfig{