40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"time"
|
|
|
|
sharedlimit "git.sendico.io/tech/sxchnge/shared/ratelimit"
|
|
)
|
|
|
|
type VerificationRateLimitsConfig struct {
|
|
PerDestination sharedlimit.WindowConfig `yaml:"per_destination"`
|
|
PerIP sharedlimit.WindowConfig `yaml:"per_ip"`
|
|
}
|
|
|
|
type VerificationRateLimits struct {
|
|
PerDestination sharedlimit.Window
|
|
PerIP sharedlimit.Window
|
|
}
|
|
|
|
func DefaultVerificationRateLimits() VerificationRateLimits {
|
|
return VerificationRateLimits{
|
|
PerDestination: sharedlimit.Window{Limit: 5, Window: time.Hour},
|
|
PerIP: sharedlimit.Window{Limit: 20, Window: time.Hour},
|
|
}
|
|
}
|
|
|
|
func (c *Config) ResolveRateLimits() (VerificationRateLimits, error) {
|
|
if c == nil || c.RateLimits == nil {
|
|
return DefaultVerificationRateLimits(), nil
|
|
}
|
|
destination, err := sharedlimit.ResolveWindow(c.RateLimits.PerDestination, "verification.rate_limits.per_destination")
|
|
if err != nil {
|
|
return VerificationRateLimits{}, err
|
|
}
|
|
ip, err := sharedlimit.ResolveWindow(c.RateLimits.PerIP, "verification.rate_limits.per_ip")
|
|
if err != nil {
|
|
return VerificationRateLimits{}, err
|
|
}
|
|
return VerificationRateLimits{PerDestination: destination, PerIP: ip}, nil
|
|
}
|