checkCollectionRateLimit checks whether the current request satisfy the rate limit configuration for the specific collection. Each baseTags entry will be prefixed with the collection name and its wildcard variant.
(e *core.RequestEvent, collection *core.Collection, baseTags ...string)
| 79 | // |
| 80 | // Each baseTags entry will be prefixed with the collection name and its wildcard variant. |
| 81 | func checkCollectionRateLimit(e *core.RequestEvent, collection *core.Collection, baseTags ...string) error { |
| 82 | if skipRateLimit(e) { |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | labels := make([]string, 0, 2+len(baseTags)*2) |
| 87 | |
| 88 | rtId := collection.Id + e.Request.Pattern |
| 89 | |
| 90 | // add first the primary labels (aka. ["collectionName:action1", "collectionName:action2"]) |
| 91 | for _, baseTag := range baseTags { |
| 92 | rtId += baseTag |
| 93 | labels = append(labels, collection.Name+":"+baseTag) |
| 94 | } |
| 95 | |
| 96 | // add the wildcard labels (aka. [..., "*:action1","*:action2", "*"]) |
| 97 | for _, baseTag := range baseTags { |
| 98 | labels = append(labels, "*:"+baseTag) |
| 99 | } |
| 100 | labels = append(labels, defaultRateLimitLabels(e)...) |
| 101 | |
| 102 | rule, ok := e.App.Settings().RateLimits.FindRateLimitRule(labels, defaultRateLimitAudience(e)...) |
| 103 | if ok { |
| 104 | return checkRateLimit(e, rtId+rule.Audience, rule) |
| 105 | } |
| 106 | |
| 107 | return nil |
| 108 | } |
| 109 | |
| 110 | // isIPInList checks if the specified IP is in a list of other individual IPs or subnets. |
| 111 | func isIPInList(ipsOrSubnets []string, ip string) bool { |
no test coverage detected
searching dependent graphs…