github.com/argoproj/argo-cd@v1.8.7/server/session/ratelimiter.go (about) 1 package session 2 3 import ( 4 util "github.com/argoproj/argo-cd/util/io" 5 "github.com/argoproj/argo-cd/util/session" 6 7 log "github.com/sirupsen/logrus" 8 "golang.org/x/sync/semaphore" 9 ) 10 11 func NewLoginRateLimiter(maxNumber int) func() (util.Closer, error) { 12 semaphore := semaphore.NewWeighted(int64(maxNumber)) 13 return func() (util.Closer, error) { 14 if !semaphore.TryAcquire(1) { 15 log.Warnf("Exceeded number of concurrent login requests") 16 return nil, session.InvalidLoginErr 17 } 18 return util.NewCloser(func() error { 19 defer semaphore.Release(1) 20 return nil 21 }), nil 22 } 23 }