baseimage-tutorial-framework/src/controller/handlers/solution_check_handler.py
2018-02-13 13:39:27 +01:00

20 lines
737 B
Python

import secrets
from tornado.web import RequestHandler, HTTPError
from tfw.config.logs import logging
log = logging.getLogger(__name__)
class SolutionCheckHandler(RequestHandler):
def initialize(self, solvable_connector, token):
self.solvable_connector = solvable_connector
self.token = token
async def get(self):
log.debug('Sending request to solvable')
self.solvable_connector.send('solution_check', {})
resp_token, resp_data = await self.solvable_connector.recv()
if not secrets.compare_digest(self.token, resp_token):
raise HTTPError(500, 'Solvable didn\'t provide initial token.')
log.debug('Received answer from solvable')
self.write(resp_data)