From 8edc187c3c089fd3b6de3ce804675e8613b299f3 Mon Sep 17 00:00:00 2001 From: Sebastian Kfuner Date: Thu, 13 Jul 2023 14:44:08 +0200 Subject: [PATCH 1/4] Added parameter to set outputfile psql_initdb Now its possible to choose where the script should save the outputfile. --- intelmq/bin/intelmq_psql_initdb.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/intelmq/bin/intelmq_psql_initdb.py b/intelmq/bin/intelmq_psql_initdb.py index c31e41167..34a95bc06 100644 --- a/intelmq/bin/intelmq_psql_initdb.py +++ b/intelmq/bin/intelmq_psql_initdb.py @@ -14,6 +14,7 @@ import os import sys import tempfile +import argparse from intelmq import HARMONIZATION_CONF_FILE @@ -22,6 +23,20 @@ 'source.abuse_contact', 'source.asn', 'source.ip', 'source.fqdn', 'time.observation', 'time.source'] +APPNAME = 'intelmq_psql_initdb' + +DESCRIPTION = """ +Generates a SQL command file with commands to create the events table. + +Reads the harmonization configuration and generates an SQL command from it. +The SQL file is saved by default in `/tmp/initdb.sql` or a temporary name +if the other one exists. +""" + +USAGE = """ + intelmq_psql_initdb [-o|--outputfile] +""" + def generate(harmonization_file=HARMONIZATION_CONF_FILE): FIELDS = {} @@ -80,7 +95,19 @@ def generate(harmonization_file=HARMONIZATION_CONF_FILE): def main(): - OUTPUTFILE = "/tmp/initdb.sql" + parser = argparse.ArgumentParser( + prog=APPNAME, + description=DESCRIPTION, + formatter_class=argparse.RawDescriptionHelpFormatter, + usage=USAGE + ) + parser.add_argument('-o', '--outputfile', + help='Defines the Ouputfile', + default='/tmp/initdb.sql' + ) + args = parser.parse_args() + + OUTPUTFILE = args.output fp = None try: if os.path.exists(OUTPUTFILE): From 404810d7c976403b2db7ee403f2c8b4403ed3e25 Mon Sep 17 00:00:00 2001 From: Sebastian Kfuner Date: Thu, 13 Jul 2023 14:49:07 +0200 Subject: [PATCH 2/4] Updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39e44f2ee..4de0d7f85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,8 @@ CHANGELOG ### Tools - `intelmqsetup`: - SECURITY: fixed a low-risk bug causing the tool to change owner of `/` if run with the `INTELMQ_PATHS_NO_OPT` environment variable set. This affects only the PIP package as the DEB/RPM packages don't contain this tool. (PR#2355 by Kamil MaƄkowski, fixes #2354) +- `intelmq_psql_initdb`: + - Added parameter `-o` to set the output file destination. (by Sebastian Kufner) ### Known Errors - `intelmq.parsers.html_table` may not process invalid URLs in patched Python version due to changes in `urllib`. See #2382 From 8411a418353f48dcfc4eea9d239f12818df4438f Mon Sep 17 00:00:00 2001 From: Sebastian Kfuner Date: Thu, 13 Jul 2023 15:33:58 +0200 Subject: [PATCH 3/4] Fixed Error --- intelmq/bin/intelmq_psql_initdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intelmq/bin/intelmq_psql_initdb.py b/intelmq/bin/intelmq_psql_initdb.py index 34a95bc06..41d1c08bb 100644 --- a/intelmq/bin/intelmq_psql_initdb.py +++ b/intelmq/bin/intelmq_psql_initdb.py @@ -107,7 +107,7 @@ def main(): ) args = parser.parse_args() - OUTPUTFILE = args.output + OUTPUTFILE = args.outputfile fp = None try: if os.path.exists(OUTPUTFILE): From 7d7d13c75818ec21b585d93fde0c21807b963636 Mon Sep 17 00:00:00 2001 From: Sebastian Kfuner Date: Thu, 13 Jul 2023 16:13:30 +0200 Subject: [PATCH 4/4] Removed hardcoded scriptname and usage Removed the hardcoded scriptname and usage in the help menu --- intelmq/bin/intelmq_psql_initdb.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/intelmq/bin/intelmq_psql_initdb.py b/intelmq/bin/intelmq_psql_initdb.py index 41d1c08bb..ff19107a7 100644 --- a/intelmq/bin/intelmq_psql_initdb.py +++ b/intelmq/bin/intelmq_psql_initdb.py @@ -23,8 +23,6 @@ 'source.abuse_contact', 'source.asn', 'source.ip', 'source.fqdn', 'time.observation', 'time.source'] -APPNAME = 'intelmq_psql_initdb' - DESCRIPTION = """ Generates a SQL command file with commands to create the events table. @@ -33,10 +31,6 @@ if the other one exists. """ -USAGE = """ - intelmq_psql_initdb [-o|--outputfile] -""" - def generate(harmonization_file=HARMONIZATION_CONF_FILE): FIELDS = {} @@ -96,10 +90,8 @@ def generate(harmonization_file=HARMONIZATION_CONF_FILE): def main(): parser = argparse.ArgumentParser( - prog=APPNAME, description=DESCRIPTION, - formatter_class=argparse.RawDescriptionHelpFormatter, - usage=USAGE + formatter_class=argparse.RawDescriptionHelpFormatter ) parser.add_argument('-o', '--outputfile', help='Defines the Ouputfile',