Documentation ¶
Index ¶
- Variables
- func CheckRateLimit(p prefixer.Prefixer, ct CounterType) error
- func CheckRateLimitKey(customKey string, ct CounterType) error
- func GetMaximumLimit(ct CounterType) int64
- func IsLimitReachedOrExceeded(err error) bool
- func ResetCounter(p prefixer.Prefixer, ct CounterType)
- func SetMaximumLimit(ct CounterType, newLimit int64)
- type Counter
- type CounterType
Constants ¶
This section is empty.
Variables ¶
var ErrRateLimitExceeded = errors.New("Rate limit exceeded")
ErrRateLimitExceeded is the error returned when the limit was already reached before the check.
var ErrRateLimitReached = errors.New("Rate limit reached")
ErrRateLimitReached is the error returned when we were under the limit before the check, and reach the limit.
Functions ¶
func CheckRateLimit ¶
func CheckRateLimit(p prefixer.Prefixer, ct CounterType) error
CheckRateLimit returns an error if the counter for the given type and instance has reached the limit.
func CheckRateLimitKey ¶
func CheckRateLimitKey(customKey string, ct CounterType) error
CheckRateLimitKey allows to check the rate-limit for a key
func GetMaximumLimit ¶
func GetMaximumLimit(ct CounterType) int64
GetMaximumLimit returns the limit of a CounterType
func IsLimitReachedOrExceeded ¶
IsLimitReachedOrExceeded return true if the limit has been reached or exceeded, false otherwise.
func ResetCounter ¶
func ResetCounter(p prefixer.Prefixer, ct CounterType)
ResetCounter sets again to zero the counter for the given type and instance.
func SetMaximumLimit ¶
func SetMaximumLimit(ct CounterType, newLimit int64)
SetMaximumLimit sets a new limit for a CounterType
Types ¶
type Counter ¶
type Counter interface { Increment(key string, timeLimit time.Duration) (int64, error) Reset(key string) error }
Counter is an interface for counting number of attempts that can be used to rate limit the number of logins and 2FA tries, and thus block bruteforce attacks.
func NewRedisCounter ¶
func NewRedisCounter(client redis.UniversalClient) Counter
NewRedisCounter returns a counter that can be mutualized between several cozy-stack processes by using redis.
type CounterType ¶
type CounterType int
CounterType os an enum for the type of counters used by rate-limiting.
const ( // AuthType is used for counting the number of login attempts. AuthType CounterType = iota // TwoFactorGenerationType is used for counting the number of times a 2FA // is generated. TwoFactorGenerationType // TwoFactorType is used for counting the number of 2FA attempts. TwoFactorType // OAuthClientType is used for counting the number of OAuth clients. // creations/updates. OAuthClientType // SharingInviteType is used for counting the number of sharing invitations // sent to a given instance. SharingInviteType // SharingPublicLinkType is used for counting the number of public sharing // link consultations SharingPublicLinkType // JobThumbnailType is used for counting the number of thumbnail jobs // executed by an instance JobThumbnailType // io.cozy.shared database JobShareTrackType JobShareReplicateType JobShareUploadType // JobKonnectorType is used for counting the number of konnector executions JobKonnectorType // JobZipType is used for cozies exports JobZipType // JobSendMailType is used for mail sending JobSendMailType // JobServiceType is used for generic services // Ex: categorization or matching for banking JobServiceType // JobNotificationType is used for mobile notifications pushing JobNotificationType // SendHintByMail is used for sending the password hint by email SendHintByMail // JobNotesPersistType is used for saving notes to the VFS JobNotesPersistType // JobClientType is used for the jobs associated to a @client trigger JobClientType // ExportType is used for creating an export of the data ExportType // WebhookTriggerType is used for calling a webhook trigger WebhookTriggerType // JobCleanClientType is used for cleaning unused OAuth clients JobCleanClientType )