]> git.ipfire.org Git - thirdparty/suricata-update.git/commitdiff
allow default et/open url to be set from env
authorJason Ish <ish@unx.ca>
Thu, 7 Dec 2017 21:58:56 +0000 (15:58 -0600)
committerJason Ish <ish@unx.ca>
Thu, 7 Dec 2017 22:16:40 +0000 (16:16 -0600)
Allows the default et/open URL to be set with the
environment variable ETOPEN_URL. Mainly useful with tests
to avoid hitting the network.

suricata/update/main.py
suricata/update/sources.py

index c2119d8591988b7c68c5ff041d45099b2bba6db6..21770f40e19ea4727d1dec79c67e57d5a4fba8e6 100644 (file)
@@ -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)
index aa942d5b29e9324f756cad7c3c8bc03c96e4eba4..083edf7452ec3c77fe8f4e0cb757c07b09539492 100644 (file)
@@ -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