from suricata.update import config
from suricata.update import sources
from suricata.update import net
+from suricata.update import exceptions
logger = logging.getLogger()
def update_sources():
local_index_filename = sources.get_index_filename()
with io.BytesIO() as fileobj:
+ url = sources.get_source_index_url()
+ logger.info("Downloading %s", url)
try:
- url = sources.get_source_index_url()
- logger.info("Downloading %s", url)
net.get(url, fileobj)
except Exception as err:
- raise Exception("Failed to download index: %s: %s" % (url, err))
+ raise exceptions.ApplicationError(
+ "Failed to download index: %s: %s" % (url, err))
if not os.path.exists(config.get_cache_dir()):
try:
os.makedirs(config.get_cache_dir())
--- /dev/null
+# Copyright (C) 2017 Open Information Security Foundation
+#
+# You can copy, redistribute or modify this Program under the terms of
+# the GNU General Public License version 2 as published by the Free
+# Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# version 2 along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+class ApplicationError(Exception):
+ pass
+
+class InvalidConfigurationError(ApplicationError):
+ pass
from suricata.update import util
from suricata.update import sources
from suricata.update import commands
+from suricata.update import exceptions
from suricata.update.version import version
try:
# single file concatenating all input rule files together.
DEFAULT_OUTPUT_RULE_FILENAME = "suricata.rules"
-class ApplicationError(Exception):
- pass
-
-class InvalidConfigurationError(ApplicationError):
- pass
-
class AllRuleMatcher(object):
"""Matcher object to match all rules. """
url = source["url"] % params
else:
if not index:
- raise ApplicationError(
+ raise exceptions.ApplicationError(
"Source index is required for source %s; "
"run suricata-update update-sources" % (source["source"]))
url = index.resolve_url(name, params)
if config.get("sources"):
for url in config.get("sources"):
if type(url) not in [type("")]:
- raise InvalidConfigurationError(
+ raise exceptions.InvalidConfigurationError(
"Invalid datatype for source URL: %s" % (str(url)))
url = url % internal_params
logger.debug("Adding source %s.", url)
def main():
try:
sys.exit(_main())
- except ApplicationError as err:
+ except exceptions.ApplicationError as err:
logger.error(err)
sys.exit(1)
return DEFAULT_SOURCE_INDEX_URL
def save_source_config(source_config):
+ if not os.path.exists(get_source_directory()):
+ logger.info("Creating directory %s", get_source_directory())
+ os.makedirs(get_source_directory())
with open(get_enabled_source_filename(source_config.name), "w") as fileobj:
fileobj.write(yaml.safe_dump(
source_config.dict(), default_flow_style=False))