mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
24 lines
593 B
Go
24 lines
593 B
Go
package session
|
|
|
|
import (
|
|
utilio "github.com/argoproj/argo-cd/v3/util/io"
|
|
"github.com/argoproj/argo-cd/v3/util/session"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
"golang.org/x/sync/semaphore"
|
|
)
|
|
|
|
func NewLoginRateLimiter(maxNumber int) func() (utilio.Closer, error) {
|
|
semaphore := semaphore.NewWeighted(int64(maxNumber))
|
|
return func() (utilio.Closer, error) {
|
|
if !semaphore.TryAcquire(1) {
|
|
log.Warnf("Exceeded number of concurrent login requests")
|
|
return nil, session.InvalidLoginErr
|
|
}
|
|
return utilio.NewCloser(func() error {
|
|
defer semaphore.Release(1)
|
|
return nil
|
|
}), nil
|
|
}
|
|
}
|