[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [gettor/master] Update how Gettor use settings and configs



commit bcd61c6c9b0a90678e10a8d4639c49445b2b5a34
Author: hiro <hiro@xxxxxxxxxxxxxx>
Date:   Fri Mar 1 15:36:38 2019 +0100

    Update how Gettor use settings and configs
---
 gettor.conf.json      |  4 ++--
 gettor/parse/email.py | 15 ++++++++-------
 scripts/process_email | 10 ++++++----
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/gettor.conf.json b/gettor.conf.json
index 4a0cd27..4a4ed9e 100644
--- a/gettor.conf.json
+++ b/gettor.conf.json
@@ -4,7 +4,7 @@
   "email_parser_logfile": "/srv/gettor.torproject.org/home/gettor-hiro/log/email_parser.log",
   "email_requests_limit": 5,
   "sendmail_interval": 10,
-  "sendmail_addr": "email@addr",
-  "sendmail_host": "host",
+  "sendmail_addr": "gettor+test@xxxxxxxxxxxxxx",
+  "sendmail_host": "localhost",
   "sendmail_port": 587
 }
diff --git a/gettor/parse/email.py b/gettor/parse/email.py
index f798320..8539743 100644
--- a/gettor/parse/email.py
+++ b/gettor/parse/email.py
@@ -27,8 +27,7 @@ from twisted.python import log
 from twisted.internet import defer
 from twisted.enterprise import adbapi
 
-from .. import PLATFORMS, EMAIL_REQUESTS_LIMIT
-from ..db import SQLite3
+from ..utils.db import SQLite3
 
 
 class AddressError(Exception):
@@ -48,12 +47,13 @@ class DKIMError(Exception):
 class EmailParser(object):
     """Class for parsing email requests."""
 
-    def __init__(self, to_addr=None, dkim=False):
+    def __init__(self, settings, to_addr=None, dkim=False):
         """
         Constructor.
 
         param (Boolean) dkim: Set dkim verification to True or False.
         """
+        self.settings = settings
         self.dkim = dkim
         self.to_addr = to_addr
 
@@ -72,6 +72,7 @@ class EmailParser(object):
         :return dict with email address and command (`links` or `help`).
         """
 
+        platforms = self.settings.get("platforms")
         log.msg("Building email message from string.", system="email parser")
         msg = message_from_string(msg_str)
 
@@ -141,7 +142,7 @@ class EmailParser(object):
         if subject:
             subject = subject.group(1)
             for word in re.split(r"\s+", subject.strip()):
-                if word.lower() in PLATFORMS:
+                if word.lower() in platforms:
                     request["command"] = "links"
                     request["platform"] = word.lower()
                     break
@@ -151,7 +152,7 @@ class EmailParser(object):
 
         if not request["command"]:
             for word in re.split(r"\s+", body_str.strip()):
-                if word.lower() in PLATFORMS:
+                if word.lower() in platforms:
                     request["command"] = "links"
                     request["platform"] = word.lower()
                     break
@@ -174,7 +175,7 @@ class EmailParser(object):
         :return: deferred whose callback/errback will log database query
         execution details.
         """
-
+        email_requests_limit = self.settings.get("email_requests_limit")
         log.msg(
             "Found request for {}.".format(request['command']),
             system="email parser"
@@ -190,7 +191,7 @@ class EmailParser(object):
                 id=hid.hexdigest(), service=request['service']
             )
 
-            if num_requests[0][0] > EMAIL_REQUESTS_LIMIT:
+            if num_requests[0][0] > email_requests_limit:
                 log.msg(
                     "Discarded. Too many requests from {}.".format(
                         hid.hexdigest
diff --git a/scripts/process_email b/scripts/process_email
index 6fbc8ca..7a8236f 100755
--- a/scripts/process_email
+++ b/scripts/process_email
@@ -15,14 +15,14 @@ from twisted.internet import defer, reactor
 
 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 from gettor.parse.email import EmailParser, AddressError, DKIMError
-
-EMAIL_PARSER_LOGFILE = "/srv/gettor.torproject.org/home/gettor-hiro/log/email_parser.log"
+from gettor.utils import options
 
 @defer.inlineCallbacks
 def process_email(message):
+    settings = options.parse_settings()
 
     try:
-        ep = EmailParser("gettor+test@xxxxxxxxxxxxxx")
+        ep = EmailParser(settings, "gettor+test@xxxxxxxxxxxxxx")
         yield defer.maybeDeferred(
             ep.parse, message
         ).addCallback(ep.parse_callback).addErrback(ep.parse_errback)
@@ -44,7 +44,9 @@ def main():
 
 
 if __name__ == '__main__':
-    log.startLogging(open(EMAIL_PARSER_LOGFILE, 'a'))
+    settings = options.parse_settings()
+    email_parser_logfile = settings.get("email_parser_logfile")
+    log.startLogging(open(email_parser_logfile, 'a'))
     log.msg("New email request received.", system="process email")
     main()
     log.msg("Email request processed.", system="process email")



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits