MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / handleAuthUpdates

Method handleAuthUpdates

sdk/cliproxy/service.go:502–560  ·  view source on GitHub ↗
(ctx context.Context, updates []watcher.AuthUpdate)

Source from the content-addressed store, hash-verified

500}
501
502func (s *Service) handleAuthUpdates(ctx context.Context, updates []watcher.AuthUpdate) {
503 if s == nil {
504 return
505 }
506 updates = coalesceAuthUpdates(updates)
507 s.cfgMu.RLock()
508 cfg := s.cfg
509 s.cfgMu.RUnlock()
510 if cfg == nil || s.coreManager == nil {
511 return
512 }
513
514 registrationCtx := coreauth.WithDeferredAPIKeyModelAliasRebuild(ctx)
515 tasks := make([]modelRegistrationTask, 0, len(updates))
516 needsPluginSync := false
517 needsAliasRebuild := false
518 for _, update := range updates {
519 switch update.Action {
520 case watcher.AuthUpdateActionAdd, watcher.AuthUpdateActionModify:
521 if update.Auth == nil || update.Auth.ID == "" {
522 continue
523 }
524 auth := s.prepareCoreAuthForModelRegistration(registrationCtx, update.Auth)
525 if auth == nil {
526 continue
527 }
528 needsAliasRebuild = true
529 authForRegistration := auth
530 tasks = append(tasks, modelRegistrationTask{
531 phase: modelRegistrationPhase(authForRegistration),
532 category: modelRegistrationCategory(authForRegistration),
533 run: func(compatCache *openAICompatibilityRegistrationCache) {
534 s.completeModelRegistrationForAuthWithCache(registrationCtx, authForRegistration, compatCache)
535 },
536 })
537 needsPluginSync = true
538 case watcher.AuthUpdateActionDelete:
539 id := update.ID
540 if id == "" && update.Auth != nil {
541 id = update.Auth.ID
542 }
543 if id == "" {
544 continue
545 }
546 s.applyCoreAuthRemoval(registrationCtx, id)
547 needsAliasRebuild = true
548 default:
549 log.Debugf("received unknown auth update action: %v", update.Action)
550 }
551 }
552
553 if needsAliasRebuild {
554 s.coreManager.RefreshAPIKeyModelAlias()
555 }
556 s.runModelRegistrationTasks(registrationCtx, tasks)
557 if needsPluginSync {
558 s.syncPluginRuntime(registrationCtx)
559 }

Callers 2

consumeAuthUpdatesMethod · 0.95
handleAuthUpdateMethod · 0.95

Tested by

no test coverage detected