Skip to content

Commit 3084b72

Browse files
committed
(feat) custom ratelimit for configuration provider
1 parent cf94356 commit 3084b72

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

rate_limit/provider.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ def get_local_rate_limits(self, scope, action, target_type_uri, **kwargs):
101101
:param kwargs: optional, additional parameters
102102
:return: the local rate limit or -1 if not set
103103
"""
104-
ttu_ratelimits = self.local_ratelimits.get(target_type_uri, [])
104+
_ratelimits = self.custom_ratelimits.get(scope, None)
105+
if not _ratelimits:
106+
_ratelimits = self.local_ratelimits
107+
ttu_ratelimits = _ratelimits.get(target_type_uri, [])
105108
if not ttu_ratelimits:
106109
ttu_ratelimits = self._get_wildcard_ratelimits(
107110
self.local_ratelimits,
@@ -157,6 +160,9 @@ def read_rate_limits_from_config(self, config_path):
157160
rates = config.get('rates', {})
158161
self.global_ratelimits = rates.get('global', {})
159162
self.local_ratelimits = rates.get('default', {})
163+
self.custom_ratelimits = {}
164+
for scope, rl in rates.get('custom', {}).items():
165+
self.custom_ratelimits[scope] = rl
160166

161167

162168
class LimesRateLimitProvider(RateLimitProvider):

0 commit comments

Comments
 (0)