Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lonelycode committed Oct 9, 2017
1 parent c3cd815 commit 95c9289
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 3 additions & 1 deletion mw_api_rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ func (k *RateLimitForAPI) EnabledForSpec() bool {

// We'll init here
k.keyName = fmt.Sprintf("apilimiter-%s%s", k.Spec.OrgID, k.Spec.APIID)

// Set last updated on each load to ensure we always use a new rate limit bucket
k.apiSess = &user.SessionState{
Rate: k.Spec.GlobalRateLimit.Rate,
Per: k.Spec.GlobalRateLimit.Per,
LastUpdated: strconv.Itoa(int(time.Now().UnixNano())), // Set last updated on each load to ensure we always use a new rate limit bucket
LastUpdated: strconv.Itoa(int(time.Now().UnixNano())),
}

return true
Expand Down
6 changes: 2 additions & 4 deletions mw_api_rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ func getRLOpenChain(spec *APISpec) http.Handler {
proxy := TykNewSingleHostReverseProxy(remote, spec)
proxyHandler := ProxyHandler(proxy, spec)
baseMid := BaseMiddleware{spec, proxy}
rlMW := &RateLimitForAPI{BaseMiddleware: baseMid}
chain := alice.New(mwList(
&IPWhiteListMiddleware{baseMid},
&VersionCheck{BaseMiddleware: baseMid},
rlMW,
&RateLimitForAPI{BaseMiddleware: baseMid},
)...).Then(proxyHandler)
return chain
}
Expand All @@ -47,14 +46,13 @@ func getGlobalRLAuthKeyChain(spec *APISpec) http.Handler {
proxy := TykNewSingleHostReverseProxy(remote, spec)
proxyHandler := ProxyHandler(proxy, spec)
baseMid := BaseMiddleware{spec, proxy}
rlMW := &RateLimitForAPI{BaseMiddleware: baseMid}
chain := alice.New(mwList(
&IPWhiteListMiddleware{baseMid},
&AuthKey{baseMid},
&VersionCheck{BaseMiddleware: baseMid},
&KeyExpired{baseMid},
&AccessRightsCheck{baseMid},
rlMW,
&RateLimitForAPI{BaseMiddleware: baseMid},
&RateLimitAndQuotaCheck{baseMid},
)...).Then(proxyHandler)
return chain
Expand Down

0 comments on commit 95c9289

Please sign in to comment.