From: Shivani Bhardwaj Date: Wed, 31 Oct 2018 15:38:02 +0000 (+0530) Subject: Add --free argument to list-sources command X-Git-Tag: 1.0.1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd48f6ad86d615c07477ab2aa9d83050ce01a0b7;p=thirdparty%2Fsuricata-update.git Add --free argument to list-sources command Add the functionality of being able to list only the free sources with the `list-sources` command. This patch differentiates a free source from a non-free source based on the availability of "subscription-url" for a particular source. This argument is also available in the help section of `list-sources` command. ``` $./suricata-update list-sources -h usage: suricata-update list-sources [-h] [-v] [-q] [-D ] [-c ] [--suricata-conf ] [--suricata ] [--suricata-version ] [--user-agent ] [--no-check-certificate] [-V] [--free] optional arguments: -h, --help show this help message and exit -v, --verbose Be more verbose -q, --quiet Be quiet, warning and error messages only -D , --data-dir Data directory (default: /var/lib/suricata) -c , --config configuration file (default: /etc/suricata/update.yaml) --suricata-conf configuration file (default: /etc/suricata/suricata.yaml) --suricata Path to Suricata program --suricata-version Override Suricata version --user-agent Set custom user-agent string --no-check-certificate Disable server SSL/TLS certificate verification -V, --version Display version --free List all freely available sources ``` Closes Redmine ticket #2641. --- diff --git a/suricata/update/commands/listsources.py b/suricata/update/commands/listsources.py index 230a99e..144f244 100644 --- a/suricata/update/commands/listsources.py +++ b/suricata/update/commands/listsources.py @@ -27,9 +27,12 @@ from suricata.update import exceptions logger = logging.getLogger() def register(parser): + parser.add_argument("--free", action="store_true", + default=False, help="List all freely available sources") parser.set_defaults(func=list_sources) def list_sources(): + free_only = config.args().free if not sources.source_index_exists(config): logger.info("No source index found, running update-sources") try: @@ -38,6 +41,9 @@ def list_sources(): logger.warning("%s: will use bundled index.", err) index = sources.load_source_index(config) for name, source in index.get_sources().items(): + is_not_free = source.get("subscribe-url") + if free_only and is_not_free: + continue print("%s: %s" % (util.bright_cyan("Name"), util.bright_magenta(name))) print(" %s: %s" % ( util.bright_cyan("Vendor"), util.bright_magenta(source["vendor"])))