Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
Signed-off-by: SudhanshuBawane <[email protected]>
  • Loading branch information
SudhanshuBawane committed Mar 6, 2024
1 parent e05e3b3 commit 037e983
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion backend/agentd/agentd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 20 additions & 18 deletions backend/agentd/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions backend/agentd/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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{
Expand Down

0 comments on commit 037e983

Please sign in to comment.