Browse Source

Token between controllers and email fetcher in config

Guénaël Muller 7 years ago
parent
commit
e0dd766c17

+ 2 - 0
tracim/development.ini.base View File

@@ -221,6 +221,8 @@ email.reply.imap.port = 993
221 221
 email.reply.imap.user = your_imap_user
222 222
 email.reply.imap.password = your_imap_password
223 223
 email.reply.imap.folder = INBOX
224
+# Token for communication between mail fetcher and tracim controller
225
+email.reply.token = mysecuretoken
224 226
 # Delay in seconds between each check
225 227
 email.reply.delay = 60
226 228
 

+ 3 - 0
tracim/tracim/config/app_cfg.py View File

@@ -376,6 +376,9 @@ class CFG(object):
376 376
         self.EMAIL_REPLY_DELAY = int(tg.config.get(
377 377
             'email.reply.delay',
378 378
         ))
379
+        self.EMAIL_REPLY_TOKEN = tg.config.get(
380
+            'email.reply.token',
381
+        )
379 382
 
380 383
         self.TRACKER_JS_PATH = tg.config.get(
381 384
             'js_tracker_path',

+ 5 - 3
tracim/tracim/controllers/events.py View File

@@ -7,15 +7,17 @@ from tracim.lib.content import ContentApi
7 7
 from tracim.lib.user import UserApi
8 8
 from tracim.model.data import ContentType
9 9
 
10
-VALID_TOKEN_VALUE="djkflhqsfhyqsdb fq"
11
-
12 10
 class EventsRestController(RestController):
13 11
 
14 12
 
15 13
     @tg.expose('json')
16 14
     def post(self):
17 15
         json = request.json_body
18
-        if 'token' in json and json['token'] == VALID_TOKEN_VALUE:
16
+
17
+        from tracim.config.app_cfg import CFG
18
+        cfg = CFG.get_instance()
19
+
20
+        if 'token' in json and json['token'] == cfg.EMAIL_REPLY_TOKEN:
19 21
             if 'user_mail' not in json or 'content_id' not in json:
20 22
                 return {'status': 'error',
21 23
                         'error': 'bad json',}

+ 1 - 0
tracim/tracim/lib/daemons.py View File

@@ -175,6 +175,7 @@ class MailFetcherDaemon(Daemon):
175 175
             delay=cfg.EMAIL_REPLY_DELAY,
176 176
             # FIXME - G.M - 2017-11-15 - proper tracim url formatting
177 177
             endpoint=cfg.WEBSITE_BASE_URL + "/events",
178
+            token=cfg.EMAIL_REPLY_TOKEN,
178 179
         )
179 180
         self._fetcher.run()
180 181
 

+ 4 - 3
tracim/tracim/lib/email_fetcher.py View File

@@ -17,7 +17,6 @@ from bs4 import BeautifulSoup
17 17
 from email_reply_parser import EmailReplyParser
18 18
 
19 19
 from tracim.lib.base import logger
20
-from tracim.controllers.events import VALID_TOKEN_VALUE
21 20
 
22 21
 TRACIM_SPECIAL_KEY_HEADER = "X-Tracim-Key"
23 22
 BS_HTML_BODY_PARSE_CONFIG = {
@@ -168,7 +167,7 @@ class MailFetcher(object):
168 167
 
169 168
     def __init__(self,
170 169
                  host: str, port: str, user: str, password: str, folder: str,
171
-                 delay: int, endpoint: str) \
170
+                 delay: int, endpoint: str, token:str) \
172 171
             -> None:
173 172
         """
174 173
         Fetch mail from a mailbox folder through IMAP and add their content to
@@ -181,6 +180,7 @@ class MailFetcher(object):
181 180
         :param folder: mail folder where new mail are fetched
182 181
         :param delay: seconds to wait before fetching new mail again
183 182
         :param endpoint: tracim http endpoint where decoded mail are send.
183
+        :param token: token to authenticate http connexion
184 184
         """
185 185
         self._connection = None
186 186
         self._mails = []
@@ -191,6 +191,7 @@ class MailFetcher(object):
191 191
         self.folder = folder
192 192
         self.delay = delay
193 193
         self.endpoint = endpoint
194
+        self.token = token
194 195
 
195 196
         self._is_active = True
196 197
 
@@ -260,7 +261,7 @@ class MailFetcher(object):
260 261
         unsended_mail = []
261 262
         while self._mails:
262 263
             mail = self._mails.pop()
263
-            msg = {"token": VALID_TOKEN_VALUE,
264
+            msg = {"token": self.token,
264 265
                    "user_mail": mail.get_from_address(),
265 266
                    "content_id": mail.get_key(),
266 267
                    "payload": {