From: Jason Ish Date: Thu, 7 Dec 2017 21:58:56 +0000 (-0600) Subject: allow default et/open url to be set from env X-Git-Tag: 1.0.0b1~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c949a9c109a122f93219ee25dce25de657a011e7;p=thirdparty%2Fsuricata-update.git allow default et/open url to be set from env Allows the default et/open URL to be set with the environment variable ETOPEN_URL. Mainly useful with tests to avoid hitting the network. --- diff --git a/suricata/update/main.py b/suricata/update/main.py index c2119d8..21770f4 100644 --- a/suricata/update/main.py +++ b/suricata/update/main.py @@ -771,22 +771,6 @@ class FileTracker: return True return False -def resolve_etopen_url(suricata_version): - # Template URL for Emerging Threats Open rules. - template_url = ("https://rules.emergingthreats.net/open/" - "suricata%(version)s/" - "emerging.rules.tar.gz") - - mappings = { - "version": "", - } - - mappings["version"] = "-%d.%d.%d" % (suricata_version.major, - suricata_version.minor, - suricata_version.patch) - - return template_url % mappings - def ignore_file(ignore_files, filename): if not ignore_files: return False @@ -916,7 +900,7 @@ def load_sources(suricata_version): if config.get("etopen") or not urls: if not urls: logger.info("No sources configured, will use Emerging Threats Open") - urls.append(resolve_etopen_url(suricata_version)) + urls.append(sources.get_etopen_url(internal_params)) # Converting the URLs to a set removed dupes. urls = set(urls) diff --git a/suricata/update/sources.py b/suricata/update/sources.py index aa942d5..083edf7 100644 --- a/suricata/update/sources.py +++ b/suricata/update/sources.py @@ -33,6 +33,8 @@ logger = logging.getLogger() DEFAULT_SOURCE_INDEX_URL = "https://www.openinfosecfoundation.org/rules/index.yaml" SOURCE_INDEX_FILENAME = "index.yaml" +DEFAULT_ETOPEN_URL = "https://rules.emergingthreats.net/open/suricata-%(__version__)s/emerging.rules.tar.gz" + def get_source_directory(): """Return the directory where source configuration files are kept.""" return os.path.join(config.get_state_dir(), config.SOURCE_DIRECTORY) @@ -162,3 +164,7 @@ def safe_filename(name): name = name.replace("/", "-") return name +def get_etopen_url(params): + if os.getenv("ETOPEN_URL"): + return os.getenv("ETOPEN_URL") % params + return DEFAULT_ETOPEN_URL % params