mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 02:01:32 +00:00
40 lines
999 B
Python
40 lines
999 B
Python
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 = {
|
|
'key': 'fsm.trigger',
|
|
'transition': self.initial_trigger
|
|
}
|
|
sign_message(self._auth_key, trigger)
|
|
self.connector.send_message(trigger)
|
|
|
|
def handle_update(self):
|
|
self.stop()
|
|
|
|
def stop(self):
|
|
pass
|