mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
fix(auth): fix runtime auth reload on oauth blacklist change
This commit is contained in:
@@ -146,6 +146,27 @@ func (s *Service) consumeAuthUpdates(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) emitAuthUpdate(ctx context.Context, update watcher.AuthUpdate) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
if s.watcher != nil && s.watcher.DispatchRuntimeAuthUpdate(update) {
|
||||
return
|
||||
}
|
||||
if s.authUpdates != nil {
|
||||
select {
|
||||
case s.authUpdates <- update:
|
||||
return
|
||||
default:
|
||||
log.Debugf("auth update queue saturated, applying inline action=%v id=%s", update.Action, update.ID)
|
||||
}
|
||||
}
|
||||
s.handleAuthUpdate(ctx, update)
|
||||
}
|
||||
|
||||
func (s *Service) handleAuthUpdate(ctx context.Context, update watcher.AuthUpdate) {
|
||||
if s == nil {
|
||||
return
|
||||
@@ -220,7 +241,11 @@ func (s *Service) wsOnConnected(channelID string) {
|
||||
Metadata: map[string]any{"email": channelID}, // metadata drives logging and usage tracking
|
||||
}
|
||||
log.Infof("websocket provider connected: %s", channelID)
|
||||
s.applyCoreAuthAddOrUpdate(context.Background(), auth)
|
||||
s.emitAuthUpdate(context.Background(), watcher.AuthUpdate{
|
||||
Action: watcher.AuthUpdateActionAdd,
|
||||
ID: auth.ID,
|
||||
Auth: auth,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) wsOnDisconnected(channelID string, reason error) {
|
||||
@@ -237,7 +262,10 @@ func (s *Service) wsOnDisconnected(channelID string, reason error) {
|
||||
log.Infof("websocket provider disconnected: %s", channelID)
|
||||
}
|
||||
ctx := context.Background()
|
||||
s.applyCoreAuthRemoval(ctx, channelID)
|
||||
s.emitAuthUpdate(ctx, watcher.AuthUpdate{
|
||||
Action: watcher.AuthUpdateActionDelete,
|
||||
ID: channelID,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) applyCoreAuthAddOrUpdate(ctx context.Context, auth *coreauth.Auth) {
|
||||
|
||||
@@ -83,9 +83,10 @@ type WatcherWrapper struct {
|
||||
start func(ctx context.Context) error
|
||||
stop func() error
|
||||
|
||||
setConfig func(cfg *config.Config)
|
||||
snapshotAuths func() []*coreauth.Auth
|
||||
setUpdateQueue func(queue chan<- watcher.AuthUpdate)
|
||||
setConfig func(cfg *config.Config)
|
||||
snapshotAuths func() []*coreauth.Auth
|
||||
setUpdateQueue func(queue chan<- watcher.AuthUpdate)
|
||||
dispatchRuntimeUpdate func(update watcher.AuthUpdate) bool
|
||||
}
|
||||
|
||||
// Start proxies to the underlying watcher Start implementation.
|
||||
@@ -112,6 +113,16 @@ func (w *WatcherWrapper) SetConfig(cfg *config.Config) {
|
||||
w.setConfig(cfg)
|
||||
}
|
||||
|
||||
// DispatchRuntimeAuthUpdate forwards runtime auth updates (e.g., websocket providers)
|
||||
// into the watcher-managed auth update queue when available.
|
||||
// Returns true if the update was enqueued successfully.
|
||||
func (w *WatcherWrapper) DispatchRuntimeAuthUpdate(update watcher.AuthUpdate) bool {
|
||||
if w == nil || w.dispatchRuntimeUpdate == nil {
|
||||
return false
|
||||
}
|
||||
return w.dispatchRuntimeUpdate(update)
|
||||
}
|
||||
|
||||
// SetClients updates the watcher file-backed clients registry.
|
||||
// SetClients and SetAPIKeyClients removed; watcher manages its own caches
|
||||
|
||||
|
||||
@@ -28,5 +28,8 @@ func defaultWatcherFactory(configPath, authDir string, reload func(*config.Confi
|
||||
setUpdateQueue: func(queue chan<- watcher.AuthUpdate) {
|
||||
w.SetAuthUpdateQueue(queue)
|
||||
},
|
||||
dispatchRuntimeUpdate: func(update watcher.AuthUpdate) bool {
|
||||
return w.DispatchRuntimeAuthUpdate(update)
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user