@@ -12,6 +12,7 @@ import (
1212
1313 "github.com/NGLSL/CLIProxyAPI/v6/internal/config"
1414 "github.com/NGLSL/CLIProxyAPI/v6/internal/util"
15+ coreauth "github.com/NGLSL/CLIProxyAPI/v6/sdk/cliproxy/auth"
1516 sdkconfig "github.com/NGLSL/CLIProxyAPI/v6/sdk/config"
1617 "github.com/gin-gonic/gin"
1718 log "github.com/sirupsen/logrus"
@@ -293,6 +294,31 @@ func normalizeRoutingStrategy(strategy string) (string, bool) {
293294 }
294295}
295296
297+ func selectorForRoutingStrategy (strategy string ) coreauth.Selector {
298+ normalized , ok := normalizeRoutingStrategy (strategy )
299+ if ! ok {
300+ normalized = "round-robin"
301+ }
302+ switch normalized {
303+ case "fill-first" :
304+ return & coreauth.FillFirstSelector {}
305+ case "sticky-round-robin" :
306+ return & coreauth.StickyRoundRobinSelector {}
307+ default :
308+ return & coreauth.RoundRobinSelector {}
309+ }
310+ }
311+
312+ func (h * Handler ) applyRoutingStrategyRuntime (strategy string ) {
313+ if h == nil || h .authManager == nil {
314+ return
315+ }
316+ h .authManager .SetSelector (selectorForRoutingStrategy (strategy ))
317+ if h .cfg != nil {
318+ h .authManager .SetConfig (h .cfg )
319+ }
320+ }
321+
296322// RoutingStrategy
297323func (h * Handler ) GetRoutingStrategy (c * gin.Context ) {
298324 strategy , ok := normalizeRoutingStrategy (h .cfg .Routing .Strategy )
@@ -316,7 +342,9 @@ func (h *Handler) PutRoutingStrategy(c *gin.Context) {
316342 return
317343 }
318344 h .cfg .Routing .Strategy = normalized
319- h .persist (c )
345+ if h .persist (c ) {
346+ h .applyRoutingStrategyRuntime (normalized )
347+ }
320348}
321349
322350// Proxy URL
0 commit comments