From 62da3aa0afdfbb18559f4ab5d97ae2ebd7281a48 Mon Sep 17 00:00:00 2001 From: Jorik Schellekens Date: Thu, 11 Jul 2019 18:21:51 +0100 Subject: Move whitelisting --- synapse/logging/opentracing.py | 57 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py index dc49fc3cd5..e9dbef0675 100644 --- a/synapse/logging/opentracing.py +++ b/synapse/logging/opentracing.py @@ -119,6 +119,36 @@ def init_tracer(config): tags = opentracing.tags +##### Whitelisting + + +@only_if_tracing +def set_homeserver_whitelist(homeserver_whitelist): + """Sets the homeserver whitelist + + Args: + homeserver_whitelist (iterable of strings): regex of whitelisted homeservers + """ + global _homeserver_whitelist + if homeserver_whitelist: + # Makes a single regex which accepts all passed in regexes in the list + _homeserver_whitelist = re.compile( + "({})".format(")|(".join(homeserver_whitelist)) + ) + + +@only_if_tracing +def whitelisted_homeserver(destination): + """Checks if a destination matches the whitelist + + Args: + destination (String)""" + global _homeserver_whitelist + if _homeserver_whitelist: + return _homeserver_whitelist.match(destination) + return False + + ##### Start spans and scopes # Could use kwargs but I want these to be explicit @@ -278,33 +308,6 @@ def set_operation_name(operation_name): opentracing.tracer.active_span.set_operation_name(operation_name) -@only_if_tracing -def set_homeserver_whitelist(homeserver_whitelist): - """Sets the homeserver whitelist - - Args: - homeserver_whitelist (iterable of strings): regex of whitelisted homeservers - """ - global _homeserver_whitelist - if homeserver_whitelist: - # Makes a single regex which accepts all passed in regexes in the list - _homeserver_whitelist = re.compile( - "({})".format(")|(".join(homeserver_whitelist)) - ) - - -@only_if_tracing -def whitelisted_homeserver(destination): - """Checks if a destination matches the whitelist - - Args: - destination (String)""" - global _homeserver_whitelist - if _homeserver_whitelist: - return _homeserver_whitelist.match(destination) - return False - - @only_if_tracing def inject_active_span_twisted_headers(headers, destination): """ -- cgit 1.4.1