Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parameter for outputfile in initdb script #2385

Merged
merged 5 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion intelmq/bin/intelmq_psql_initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import sys
import tempfile
import argparse

from intelmq import HARMONIZATION_CONF_FILE

Expand All @@ -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 = {}
Expand Down Expand Up @@ -80,7 +95,19 @@ def generate(harmonization_file=HARMONIZATION_CONF_FILE):


def main():
OUTPUTFILE = "/tmp/initdb.sql"
parser = argparse.ArgumentParser(
prog=APPNAME,
sebkuf marked this conversation as resolved.
Show resolved Hide resolved
description=DESCRIPTION,
formatter_class=argparse.RawDescriptionHelpFormatter,
usage=USAGE
sebkuf marked this conversation as resolved.
Show resolved Hide resolved
)
parser.add_argument('-o', '--outputfile',
help='Defines the Ouputfile',
default='/tmp/initdb.sql'
)
args = parser.parse_args()

OUTPUTFILE = args.outputfile
fp = None
try:
if os.path.exists(OUTPUTFILE):
Expand Down