mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 20:01:33 +00:00
Share token with solvable upon starting
This commit is contained in:
parent
0cd294d61f
commit
019ce53b39
@ -5,11 +5,13 @@ from tfw.networking.serialization import deserialize_all, serialize_all
|
|||||||
class ControllerResponder:
|
class ControllerResponder:
|
||||||
def __init__(self, fsm):
|
def __init__(self, fsm):
|
||||||
self.fsm = fsm
|
self.fsm = fsm
|
||||||
|
self.token = None
|
||||||
self.controller_connector = ControllerConnector()
|
self.controller_connector = ControllerConnector()
|
||||||
self.controller_connector.register_callback(self.handle_controller_request)
|
self.controller_connector.register_callback(self.handle_controller_request)
|
||||||
self.controller_request_handlers = {
|
self.controller_request_handlers = {
|
||||||
'solution_check': self.handle_solution_check_request,
|
'solution_check': self.handle_solution_check_request,
|
||||||
'test': self.handle_test_request
|
'test': self.handle_test_request,
|
||||||
|
'token': self.handle_token_request
|
||||||
}
|
}
|
||||||
|
|
||||||
def handle_controller_request(self, stream, msg_parts):
|
def handle_controller_request(self, stream, msg_parts):
|
||||||
@ -20,6 +22,11 @@ class ControllerResponder:
|
|||||||
def handle_test_request(self, data):
|
def handle_test_request(self, data):
|
||||||
return 'OK'
|
return 'OK'
|
||||||
|
|
||||||
|
def handle_token_request(self, data):
|
||||||
|
if self.token is None:
|
||||||
|
self.token = data
|
||||||
|
return {'token': self.token}
|
||||||
|
|
||||||
def handle_solution_check_request(self, data):
|
def handle_solution_check_request(self, data):
|
||||||
return {
|
return {
|
||||||
'solved': self.fsm.is_solved(),
|
'solved': self.fsm.is_solved(),
|
||||||
|
@ -8,13 +8,21 @@ from handlers import SolutionCheckHandler, TestHandler
|
|||||||
from tfw.networking.async_solvable_connector import AsyncSolvableConnector
|
from tfw.networking.async_solvable_connector import AsyncSolvableConnector
|
||||||
|
|
||||||
from tfw.config.logs import logging
|
from tfw.config.logs import logging
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
async def setup_token(solvable_connector, token):
|
||||||
|
solvable_connector.send('token', token)
|
||||||
|
key, data = await solvable_connector.recv()
|
||||||
|
log.debug('Token setup is done.')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'solvable_connector': AsyncSolvableConnector(),
|
'solvable_connector': AsyncSolvableConnector(),
|
||||||
'token': secrets.token_hex(32)
|
'token': secrets.token_hex(32)
|
||||||
}
|
}
|
||||||
|
IOLoop.instance().add_callback(setup_token, **kwargs)
|
||||||
routes = [
|
routes = [
|
||||||
(r'/{secret}/?'.format(secret=taoenv.SECRET), SolutionCheckHandler, kwargs),
|
(r'/{secret}/?'.format(secret=taoenv.SECRET), SolutionCheckHandler, kwargs),
|
||||||
(r'/{secret}/test/?'.format(secret=taoenv.SECRET), TestHandler, kwargs)
|
(r'/{secret}/test/?'.format(secret=taoenv.SECRET), TestHandler, kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user