mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 01:31:32 +00:00
35 lines
1014 B
Python
35 lines
1014 B
Python
import logging
|
|
|
|
from tfw.internals.crypto import KeyManager, verify_message
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class FSMAware:
|
|
keys = ['fsm.update']
|
|
|
|
def __init__(self):
|
|
self.fsm_state = None
|
|
self.fsm_in_accepted_state = False
|
|
self.fsm_event_log = []
|
|
self._auth_key = KeyManager().auth_key
|
|
|
|
def process_message(self, message):
|
|
if message['key'] == 'fsm.update':
|
|
if verify_message(self._auth_key, message):
|
|
self._handle_fsm_update(message)
|
|
|
|
def _handle_fsm_update(self, message):
|
|
try:
|
|
new_state = message['current_state']
|
|
if self.fsm_state != new_state:
|
|
self.handle_fsm_step(message)
|
|
self.fsm_state = new_state
|
|
self.fsm_in_accepted_state = message['in_accepted_state']
|
|
self.fsm_event_log.append(message)
|
|
except KeyError:
|
|
LOG.error('Invalid fsm_update message received!')
|
|
|
|
def handle_fsm_step(self, message):
|
|
pass
|