2019-06-10 13:32:45 +00:00
|
|
|
import logging
|
|
|
|
|
2019-07-24 13:17:16 +00:00
|
|
|
from tfw.internals.crypto import KeyManager, verify_message
|
2018-07-25 13:31:03 +00:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class FSMAware:
|
2019-08-08 12:45:59 +00:00
|
|
|
keys = ['fsm.update']
|
2018-07-25 13:31:03 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.fsm_state = None
|
|
|
|
self.fsm_in_accepted_state = False
|
2018-07-30 07:25:19 +00:00
|
|
|
self.fsm_event_log = []
|
2018-07-25 13:31:03 +00:00
|
|
|
self._auth_key = KeyManager().auth_key
|
|
|
|
|
2019-07-12 21:25:16 +00:00
|
|
|
def process_message(self, message):
|
2019-08-08 12:45:59 +00:00
|
|
|
if message['key'] == 'fsm.update':
|
2019-07-12 21:25:16 +00:00
|
|
|
if verify_message(self._auth_key, message):
|
|
|
|
self._handle_fsm_update(message)
|
2018-07-25 13:31:03 +00:00
|
|
|
|
|
|
|
def _handle_fsm_update(self, message):
|
|
|
|
try:
|
2019-07-12 21:25:16 +00:00
|
|
|
new_state = message['current_state']
|
2018-07-25 13:31:03 +00:00
|
|
|
if self.fsm_state != new_state:
|
2019-07-12 21:25:16 +00:00
|
|
|
self.handle_fsm_step(message)
|
2018-07-25 13:31:03 +00:00
|
|
|
self.fsm_state = new_state
|
2019-07-12 21:25:16 +00:00
|
|
|
self.fsm_in_accepted_state = message['in_accepted_state']
|
|
|
|
self.fsm_event_log.append(message)
|
2018-07-25 13:31:03 +00:00
|
|
|
except KeyError:
|
|
|
|
LOG.error('Invalid fsm_update message received!')
|
|
|
|
|
2019-07-12 21:25:16 +00:00
|
|
|
def handle_fsm_step(self, message):
|
|
|
|
pass
|