From 3e79ae1bfe708845d6a82ca9a72daf1fd65c26bb Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 6 Feb 2018 09:33:07 +0000 Subject: [PATCH] Encapsulate domain list in class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code shouldn’t be accessing this list directly; the class should provide a sensible interface to the data. --- app/config.py | 33 --------------------------------- app/utils.py | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/app/config.py b/app/config.py index fdb87bad0..b9f9e4822 100644 --- a/app/config.py +++ b/app/config.py @@ -69,39 +69,6 @@ class Config(object): STATSD_HOST = "statsd.hostedgraphite.com" STATSD_PORT = 8125 NOTIFY_ENVIRONMENT = 'development' - - EMAIL_DOMAIN_REGEXES = [ - r"gov\.uk", - r"mod\.uk", - r"mil\.uk", - r"ddc-mod\.org", - r"slc\.co\.uk", - r"gov\.scot", - r"parliament\.uk", - r"nhs\.uk", - r"nhs\.net", - r"police\.uk", - r"dclgdatamart\.co\.uk", - r"ucds\.email", - r"naturalengland\.org\.uk", - r"hmcts\.net", - r"scotent\.co\.uk", - r"assembly\.wales", - r"cjsm\.net", - r"cqc\.org\.uk", - r"bl\.uk", - r"stfc\.ac\.uk", - r"wmfs\.net", - r"bbsrc\.ac\.uk", - r"acas\.org\.uk", - r"gov\.wales", - r"biglotteryfund\.org\.uk", - r"marinemanagement\.org\.uk", - r"britishmuseum\.org", - r"derrystrabane\.com", - r"highwaysengland\.co\.uk", - ] - LOGO_UPLOAD_BUCKET_NAME = 'public-logos-local' ROUTE_SECRET_KEY_1 = os.environ.get('ROUTE_SECRET_KEY_1', '') ROUTE_SECRET_KEY_2 = os.environ.get('ROUTE_SECRET_KEY_2', '') diff --git a/app/utils.py b/app/utils.py index 1aaa19eb1..b7d9d352a 100644 --- a/app/utils.py +++ b/app/utils.py @@ -438,9 +438,41 @@ class NotGovernmentDomain(Exception): class GovernmentDomain: + domains = [ + r"gov\.uk", + r"mod\.uk", + r"mil\.uk", + r"ddc-mod\.org", + r"slc\.co\.uk", + r"gov\.scot", + r"parliament\.uk", + r"nhs\.uk", + r"nhs\.net", + r"police\.uk", + r"dclgdatamart\.co\.uk", + r"ucds\.email", + r"naturalengland\.org\.uk", + r"hmcts\.net", + r"scotent\.co\.uk", + r"assembly\.wales", + r"cjsm\.net", + r"cqc\.org\.uk", + r"bl\.uk", + r"stfc\.ac\.uk", + r"wmfs\.net", + r"bbsrc\.ac\.uk", + r"acas\.org\.uk", + r"gov\.wales", + r"biglotteryfund\.org\.uk", + r"marinemanagement\.org\.uk", + r"britishmuseum\.org", + r"derrystrabane\.com", + r"highwaysengland\.co\.uk", + ] + def __init__(self, email_address_or_domain): - for domain in current_app.config['EMAIL_DOMAIN_REGEXES']: + for domain in self.domains: if re.search( r"[\.|@]({})$".format(domain), email_address_or_domain.lower()