Skip to content

Commit

Permalink
fix domain cache verification and add cache timeout config
Browse files Browse the repository at this point in the history
  • Loading branch information
rasoro committed Jan 20, 2025
1 parent abadd8b commit b65ea6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type Configuration struct {

RestrictDomains bool `default:"false" env:"WWC_RESTRICT_DOMAINS"`

FlowsURL string `default:"flows.weni.ai" env:"WWC_FLOWS_URL"`
FlowsURL string `default:"flows.weni.ai" env:"WWC_FLOWS_URL"`
MemCacheTimeout int64 `default:"5" env:"WWC_MEM_CACHE_TIMEOUT"`
}

type S3 struct {
Expand Down
5 changes: 3 additions & 2 deletions pkg/websocket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,16 @@ func CheckAllowedDomain(app *App, channelUUID string, originDomain string) bool
var allowedDomains []string = nil
var err error
cachedDomains, notexpired := cacheChannelDomains.Get(channelUUID)
if !notexpired {
if notexpired {
allowedDomains = cachedDomains
} else {
allowedDomains, err = app.FlowsClient.GetChannelAllowedDomains(channelUUID)
if err != nil {
log.Error("Error on get allowed domains", err)
return false
}
cacheChannelDomains.Set(channelUUID, allowedDomains, time.Minute*5)
cacheTimeout := config.Get().MemCacheTimeout
cacheChannelDomains.Set(channelUUID, allowedDomains, time.Minute*time.Duration(cacheTimeout))
}
if len(allowedDomains) > 0 {
for _, domain := range allowedDomains {
Expand Down

0 comments on commit b65ea6c

Please sign in to comment.