1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-12-04 19:11:33 +00:00

Fix webservice

This commit is contained in:
Kristóf Tóth 2019-11-21 13:31:39 +01:00
parent 9d24f797df
commit b60dbc8471
2 changed files with 38 additions and 3 deletions

View File

@ -0,0 +1,29 @@
from os import mkfifo, remove
from os.path import join
from contextlib import suppress
from json import dumps
from pipe_io import PipeWriter
TFW_PIPES_DIR = '/run/tfw'
class TFWUplink:
def __init__(self):
self._send_pipe = join(TFW_PIPES_DIR, 'webservice_send')
with suppress(FileExistsError):
mkfifo(self._send_pipe)
self._pipe_writer = PipeWriter(self._send_pipe)
def send_message(self, message):
self._pipe_writer.send_message(dumps(message).encode())
def __enter__(self):
return self
def __exit__(self, type_, value, traceback):
self.close()
def close(self):
self._pipe_writer.close()
remove(self._send_pipe)

View File

@ -1,4 +1,4 @@
from pipe_io import PipeWriter
from tfw_uplink import TFWUplink
from crypto import PasswordHasher
from model import User
from errors import InvalidCredentialsError, UserExistsError
@ -9,8 +9,14 @@ class UserOps:
self.username = username
self.password = password
self.db_session = db_session
self.pipe = PipeWriter('/tmp/tfw_bot_send')
self.log = lambda message: self.pipe.send_message(message.encode()+b"\n")
self._uplink = TFWUplink()
def log(self, message):
self._uplink.send_message({
'key': 'message.send',
'originator': 'webservice',
'message': message
})
def authenticate(self):
"""