Skip to content

Commit

Permalink
Implement option of whitelisting IPs (#265)
Browse files Browse the repository at this point in the history
Bug: T204955
Change-Id: Id86539282d2b1306f65f5981d1d416aa16f30cd7
  • Loading branch information
Ladsgroup authored and adamwight committed Sep 21, 2018
1 parent eab8437 commit 0ee85a3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ores/scoring_systems/scoring_system.py
Expand Up @@ -20,7 +20,8 @@ class ScoringSystem(dict):

def __init__(self, context_map, score_cache=None,
metrics_collector=None, timeout=None, lock_manager=None,
connections_per_ip=4, connections_per_ip_hard=7):
connections_per_ip=4, connections_per_ip_hard=7,
whitelisted_ips=[]):
super().__init__()
self.update(context_map)
self.score_cache = score_cache or Empty()
Expand All @@ -29,6 +30,7 @@ def __init__(self, context_map, score_cache=None,
self.connections_per_ip = connections_per_ip
self.connections_per_ip_hard = connections_per_ip_hard
self.lock_manager = lock_manager
self.whitelisted_ips = whitelisted_ips

def check_context_models(self, request):

Expand All @@ -45,7 +47,8 @@ def score(self, request):
locked = None
start = time.time()
if request.ip and (not request.precache) and \
self.lock_manager is not None:
self.lock_manager is not None and \
request.ip not in self.whitelisted_ips:
locked = self._lock_ip(request.ip)
self.metrics_collector.lock_acquired(
'poolcounter',
Expand Down Expand Up @@ -309,11 +312,13 @@ def _kwargs_from_config(cls, config, name, section_key="scoring_systems"):
timeout = section.get('timeout')
connections_per_ip = section.get('connections_per_ip', 4)
connections_per_ip_hard = section.get('connections_per_ip', 7)
whitelisted_ips = section.get('whitelisted_ips', [])

return {'context_map': context_map, 'score_cache': score_cache,
'metrics_collector': metrics_collector, 'timeout': timeout,
'connections_per_ip': connections_per_ip,
'connections_per_ip_hard': connections_per_ip_hard,
'whitelisted_ips': whitelisted_ips,
'lock_manager': pool_counter}

@classmethod
Expand Down

0 comments on commit 0ee85a3

Please sign in to comment.