| 262 | } |
| 263 | |
| 264 | func (c *Client) runWatcher() { |
| 265 | defer func() { |
| 266 | c.Stop() |
| 267 | }() |
| 268 | for { |
| 269 | select { |
| 270 | case <-c.Done(): |
| 271 | return |
| 272 | case <-c.ctx.Done(): |
| 273 | return |
| 274 | case event, ok := <-c.consumer.Watch(): |
| 275 | if !ok { |
| 276 | slog.InfoContext(c.ctx, "watcher closed") |
| 277 | return |
| 278 | } |
| 279 | if event.EntityType != common.UserEntityType { |
| 280 | continue |
| 281 | } |
| 282 | |
| 283 | user, ok := event.Payload.(params.User) |
| 284 | if !ok { |
| 285 | slog.ErrorContext(c.ctx, "failed to cast payload to user") |
| 286 | continue |
| 287 | } |
| 288 | |
| 289 | if user.ID != c.userID { |
| 290 | continue |
| 291 | } |
| 292 | |
| 293 | if event.Operation == common.DeleteOperation { |
| 294 | slog.InfoContext(c.ctx, "user deleted; closing connection") |
| 295 | c.Stop() |
| 296 | return |
| 297 | } |
| 298 | |
| 299 | if !user.Enabled { |
| 300 | slog.InfoContext(c.ctx, "user disabled; closing connection") |
| 301 | c.Stop() |
| 302 | return |
| 303 | } |
| 304 | |
| 305 | if user.Generation != c.passwordGeneration { |
| 306 | slog.InfoContext(c.ctx, "password generation mismatch; closing connection") |
| 307 | c.Stop() |
| 308 | return |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | func IsErrorOfInterest(err error) bool { |
| 315 | if err == nil { |