sys4 / tlsrpt

A set of libraries and tools to implement TLSRPT reporting into an MTA and to generate and submit TLSRPT reports.
Other
1 stars 2 forks source link

robustness #24

Open andreasschulze opened 4 hours ago

andreasschulze commented 4 hours ago

when calling tlsrpt-* scripts without any parameter, users should see a meaningful message. Currently, python Traceback happen.

# tlsrpt-reporter 
Traceback (most recent call last):
  File "/usr/local/bin/tlsrpt-reporter", line 8, in <module>
    sys.exit(tlsrpt_reporter_main())
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pytlsrpt/tlsrpt.py", line 1333, in tlsrpt_reporter_main
    reporter.run_loop()
  File "/usr/local/lib/python3.11/dist-packages/pytlsrpt/tlsrpt.py", line 1157, in run_loop
    self.send_out_reports()
  File "/usr/local/lib/python3.11/dist-packages/pytlsrpt/tlsrpt.py", line 1106, in send_out_reports
    if self.send_out_report(day, dom, d_r_id, uniqid, destination, report):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pytlsrpt/tlsrpt.py", line 1088, in send_out_report
    return self.send_out_report_to_mail(day, dom, d_r_id, uniqid, destination, zreport)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pytlsrpt/tlsrpt.py", line 1016, in send_out_report_to_mail
    msg.add_header("Message-ID", email.utils.make_msgid(domain=msg["From"].groups[0].addresses[0].domain))
                                                               ~~~~~~~~~~~~~~~~~~^^^
IndexError: tuple index out of range

reason in this case: contact_info was unset

# tlsrpt-fetcher  
Usage: %s day [domain]
root@tlsrpt-receiver:/# tlsrpt-receiver 
Traceback (most recent call last):
  File "/usr/local/bin/tlsrpt-receiver", line 8, in <module>
    sys.exit(tlsrpt_receiver_main())
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pytlsrpt/tlsrpt.py", line 1222, in tlsrpt_receiver_main
    raise Exception("No receiver_socketname configured")
Exception: No receiver_socketname configured

reason here: receiver_socketname was unset

uwekamper commented 3 hours ago

The Python 'argparse' library can display a help text ("Usage info") when required arguments are omitted:

BLohner commented 2 hours ago

I agree that all those errors need to be catched and some useful message must be given.

However, unfortunately argparse is not the only source of configuration, so we can´t just switch certain arguments to mandatory. That mechanism will be used for the tlsrpt-fetcher process which needs to be called with one or two positional arguments (day and domain), but it cannot be used for all the configuration settings which could also come from the environment or a configuration file.