Skip to content

Commit

Permalink
Revert "Add whatsapp usage limit"
Browse files Browse the repository at this point in the history
This reverts commit 12fe613, reversing
changes made to 675a409.
  • Loading branch information
louischan-oursky committed Jun 27, 2023
1 parent 08b88fb commit 96bf8cc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 69 deletions.
15 changes: 3 additions & 12 deletions pkg/lib/config/feature_messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ var _ = FeatureConfigSchema.Add("MessagingFeatureConfig", `
"properties": {
"rate_limits": { "$ref": "#/$defs/MessagingRateLimitsFeatureConfig" },
"sms_usage": { "$ref": "#/$defs/UsageLimitConfig" },
"email_usage": { "$ref": "#/$defs/UsageLimitConfig" },
"whatsapp_usage": { "$ref": "#/$defs/UsageLimitConfig" }
"email_usage": { "$ref": "#/$defs/UsageLimitConfig" }
}
}
`)

type MessagingFeatureConfig struct {
RateLimits *MessagingRateLimitsFeatureConfig `json:"rate_limits,omitempty"`

SMSUsage *UsageLimitConfig `json:"sms_usage,omitempty"`
EmailUsage *UsageLimitConfig `json:"email_usage,omitempty"`
WhatsappUsage *UsageLimitConfig `json:"whatsapp_usage,omitempty"`
SMSUsage *UsageLimitConfig `json:"sms_usage,omitempty"`
EmailUsage *UsageLimitConfig `json:"email_usage,omitempty"`
}

func (c *MessagingFeatureConfig) SetDefaults() {
Expand All @@ -36,13 +34,6 @@ func (c *MessagingFeatureConfig) SetDefaults() {
Quota: 100000,
}
}
if c.WhatsappUsage.Enabled == nil {
c.WhatsappUsage = &UsageLimitConfig{
Enabled: newBool(true),
Period: UsageLimitPeriodMonth,
Quota: 100000,
}
}
}

var _ = FeatureConfigSchema.Add("MessagingRateLimitsFeatureConfig", `
Expand Down
4 changes: 0 additions & 4 deletions pkg/lib/config/testdata/default_feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ messaging:
enabled: true
period: month
quota: 100000
whatsapp_usage:
enabled: true
period: month
quota: 100000
collaborator: {}
web3:
nft:
Expand Down
54 changes: 2 additions & 52 deletions pkg/lib/messaging/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import (
)

const (
usageLimitEmail usage.LimitName = "Email"
usageLimitSMS usage.LimitName = "SMS"
usageLimitWhatsapp usage.LimitName = "Whatsapp"
usageLimitEmail usage.LimitName = "Email"
usageLimitSMS usage.LimitName = "SMS"
)

const (
Expand Down Expand Up @@ -165,52 +164,3 @@ func (l *Limits) checkSMS(phoneNumber string) (msg *message, err error) {

return
}

func (l *Limits) checkWhatsapp(phoneNumber string) (msg *message, err error) {
msg = &message{
logger: l.Logger,
rateLimiter: l.RateLimiter,
usageLimiter: l.UsageLimiter,
}
defer func() {
if err != nil {
// Return reserved tokens
msg.Close()
msg = nil
}
}()

msg.usageLimit, err = l.UsageLimiter.Reserve(usageLimitWhatsapp, l.FeatureConfig.WhatsappUsage)
if err != nil {
return
}

// TODO: Use whatsapp specific rate limits
msg.rateLimits, err = l.check(msg.rateLimits,
l.EnvConfig.SMSPerIP, l.FeatureConfig.RateLimits.SMSPerIP, l.Config.SMSPerIP,
MessagingSMSPerIP, string(l.RemoteIP),
)
if err != nil {
return
}

// TODO: Use whatsapp specific rate limits
msg.rateLimits, err = l.check(msg.rateLimits,
l.EnvConfig.SMSPerTarget, l.FeatureConfig.RateLimits.SMSPerTarget, l.Config.SMSPerTarget,
MessagingSMSPerTarget, phoneNumber,
)
if err != nil {
return
}

// TODO: Use whatsapp specific rate limits
msg.rateLimits, err = l.check(msg.rateLimits,
l.EnvConfig.SMS, l.FeatureConfig.RateLimits.SMS, l.Config.SMS,
MessagingSMS,
)
if err != nil {
return
}

return
}
3 changes: 2 additions & 1 deletion pkg/lib/messaging/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (s *Sender) PrepareSMS(phoneNumber string, msgType nonblocking.MessageType)
}

func (s *Sender) PrepareWhatsapp(phoneNumber string, msgType nonblocking.MessageType) (*WhatsappMessage, error) {
msg, err := s.Limits.checkWhatsapp(phoneNumber)
// FIXME: Should use a separated limit
msg, err := s.Limits.checkSMS(phoneNumber)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 96bf8cc

Please sign in to comment.