2019-08-27 11:15:59 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from tfw.internals.crypto import KeyManager, sign_message
|
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class FrontendReadyHandler:
|
|
|
|
keys = ['frontend.ready', 'fsm.update']
|
|
|
|
|
|
|
|
def __init__(self, initial_trigger):
|
|
|
|
self.connector = None
|
|
|
|
self._auth_key = KeyManager().auth_key
|
|
|
|
self.initial_trigger = initial_trigger
|
|
|
|
|
|
|
|
self.commands = {
|
|
|
|
'frontend.ready': self.handle_ready,
|
|
|
|
'fsm.update': self.handle_update
|
|
|
|
}
|
|
|
|
|
|
|
|
def handle_event(self, message, _):
|
|
|
|
try:
|
|
|
|
self.commands[message['key']]()
|
|
|
|
except KeyError:
|
|
|
|
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)
|
|
|
|
|
|
|
|
def handle_ready(self):
|
|
|
|
trigger = {
|
2019-08-28 14:31:43 +00:00
|
|
|
'key': 'fsm.trigger',
|
|
|
|
'transition': self.initial_trigger
|
2019-08-27 11:15:59 +00:00
|
|
|
}
|
|
|
|
sign_message(self._auth_key, trigger)
|
|
|
|
self.connector.send_message(trigger)
|
|
|
|
|
|
|
|
def handle_update(self):
|
|
|
|
self.stop()
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
pass
|