def get(self, id=None): """return all history according to the project-id""" user_profile = get_user(request=self.request) log_index = self.request.args.get("log_index", 0) workspace = self.request.args.get("workspace", "common") rsp = {"cmd": self.request.path} if id is not None: success, details = executionstorage.get_status(job_id=id, user=user_profile) if success != constant.OK: raise HTTP_500(details) rsp.update(details) success, details = executionstorage.get_logs(job_id=id, user=user_profile, index=log_index) if success != constant.OK: raise HTTP_500(details) rsp.update(details) else: success, details = executionstorage.get_results(workspace=workspace, user=user_profile) if success != constant.OK: raise HTTP_500(details) rsp.update({"listing": details} ) return rsp
def post(self): """Add a new task""" user_profile = get_user(request=self.request) yaml_file = self.request.data.get("yaml-file") yaml_content = self.request.data.get("yaml-content") if yaml_file is None and yaml_content is None: raise EmptyValue("yaml content or file is expected") workspace = self.request.data.get("workspace", "common") sched_mode = self.request.data.get("mode", 0) sched_at = self.request.data.get("schedule-at", (0, 0, 0, 0, 0, 0) ) if sched_mode not in constant.SCHED_MODE: raise HTTP_400("invalid sched mode") success, details = jobsmanager.schedule_job( user=user_profile, job_descr=yaml_content, job_file=yaml_file, workspace=workspace, sched_mode=sched_mode, sched_at=sched_at, ) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "job successfully scheduled", "id": details}
def post(self): """add user""" user_profile = get_user(request=self.request) # checking level access to this ressource if not user_profile['role'] == constant.ROLE_ADMIN: raise HTTP_403("access refused") # checking query request login = self.request.data.get("login") if login is None: raise HTTP_400("login is expected") if not len(login): raise HTTP_400("login name cannot be empty") password = self.request.data.get("password") if password is None: raise HTTP_400("password is expected") if not len(password): raise HTTP_400("password name cannot be empty") role = self.request.data.get("role") if role not in constant.ROLE_LIST: raise HTTP_400("bad role provided") success, details = usersmanager.add_user(role=role, login=login, password=password) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "user successfully added"}
def get(self, login=None): """get users""" user_profile = get_user(request=self.request) # return all users if login is None: # security checks if user_profile['role'] != constant.ROLE_ADMIN: raise HTTP_403("access refused") success, details = usersmanager.get_users() # return one user else: login = fix_encoding_uri_param(login) # security checks if user_profile['role'] != constant.ROLE_ADMIN: if user_profile["login"] != login: raise HTTP_403("access refused") #if login not in success, details = usersmanager.get_user(login=login) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "users": details}
def patch(self, login): """update user""" user_profile = get_user(request=self.request) login = fix_encoding_uri_param(login) if user_profile['role'] != constant.ROLE_ADMIN: if user_profile["login"] != login: raise HTTP_403("access denied") cur_pwd = self.request.data.get("current-password") if cur_pwd is None: raise HTTP_400("Current password is expected") new_pwd = self.request.data.get("new-password") if new_pwd is None: raise HTTP_400("New password is expected") if not len(new_pwd): raise HTTP_400("password name cannot be empty") success, details = usersmanager.update_pwd(login=login, new_pwd=new_pwd, cur_pwd=cur_pwd) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "password successfully updated"}
def get(self, file_path): """get files""" user_profile = _get_user(request=self.request) try: projectId = self.request.args.get("workspace", 1) file_path = fix_encoding_uri_param(file_path) except EmptyValue as e: raise HTTP_400("%s" % e) except Exception as e: raise HTTP_400("Invalid request provided (%s ?)" % e) _check_project_permissions( user_login=user_profile['login'], project_id=projectId) # avoid directory traversal file_path = os.path.normpath("/" + file_path) success, _, _, _, _, content, _, _= RepoTests.instance().getFile(pathFile=file_path, binaryMode=True, project=projectId, addLock=False, b64encode=True) if success != Context.instance().CODE_OK: raise HTTP_500("Unable to download file") return {"cmd": self.request.path, "file-content": content}
def before(self): if self.request.method == 'OPTIONS': return user = None token = self._parse_auth_header() if token: try: payload = jwt_auth.decode_token(token, self.audience) user_id = payload.get('id') user = rpc_call('get_vk_user', user_id) if not user: raise HTTP_403("Access denied") except jwt_auth.DecodeError as e: self.logger.warning(e) raise HTTP_401("Unable to parse authentication token") except jwt_auth.ExpiredSignatureError: if 'guest' not in self.audience: raise HTTP_401("Expired token") except jwt_auth.InvalidAudienceError: raise HTTP_403("Incorrect claims") except Exception as e: self.logger.exception(e) raise HTTP_500("Unable to parse authentication token") elif 'guest' not in self.audience: raise HTTP_403("Access denied") self.user = user or {}
def get(self): """Return one project according to id or all""" success, details = workspacesmanager.get_workspaces() if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "workspaces": details}
def get(self, entry_name=None): """return one entry according to id or all""" workspace = self.request.args.get("workspace", "common") success, details = globalsmanager.get_entries(workspace=workspace) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "globals": details}
def delete(self, id): """delete task, kill or cancel according to the current state""" user_profile = get_user(request=self.request) success, details = jobsmanager.delete_job(id=id, user=user_profile) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "job successfully deleted"}
def delete(self, id=None): """delete result""" user_profile = get_user(request=self.request) success, details = executionstorage.del_result(job_id=id, user=user_profile) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "success"}
def delete(self, login): """delete user""" user_profile = get_user(request=self.request) login = fix_encoding_uri_param(login) if user_profile['role'] != constant.ROLE_ADMIN: raise HTTP_403("access refused") success, details = usersmanager.reset_pwd(login=login) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "password successfully reseted"}
def post(self, file_path): """upload file""" user_profile = _get_user(request=self.request) if user_profile['monitor']: raise HTTP_403("Access refused") try: projectId = self.request.args.get("workspace", 1) file_path = fix_encoding_uri_param(file_path) fileContent = self.request.data.get("file-content") if fileContent is None: raise EmptyValue("Please specify a file content") except EmptyValue as e: raise HTTP_400("%s" % e) except Exception as e: raise HTTP_400("Invalid request provided (%s ?)" % e) _check_project_permissions( user_login=user_profile['login'], project_id=projectId) try: filePath = os.path.normpath(file_path) p = pathlib.Path(filePath) fileExt = p.suffix[1:] fileName = p.stem filePath = filePath.rsplit("%s%s" %(p.stem, p.suffix))[0] except Exception as e: raise HTTP_403('Invalid file name: %s' % e) success, _, _, _, _, _, _, _, _ = RepoTests.instance().uploadFile(pathFile=filePath, nameFile=fileName, extFile=fileExt, contentFile=fileContent, login=user_profile['login'], project=projectId, overwriteFile=True, createFolders=True, lockMode=False, binaryMode=True) if success != Context.instance().CODE_OK: raise HTTP_500("Unable to upload file") return {"cmd": self.request.path, "message": "success"}
def delete(self, item_path): """delete item like a file or folder""" user_profile = get_user(request=self.request) workspace = self.request.args.get("workspace", "common") item_path = fix_encoding_uri_param(item_path) success, details = snippetstorage.instance().delete(item_path=item_path, workspace=workspace, user=user_profile) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": details}
def delete(self, name): """Delete a workpsace, only for administrator""" user_profile = get_user(request=self.request) name = fix_encoding_uri_param(name) # checking level access to this ressource if user_profile['role'] != constant.ROLE_ADMIN: raise HTTP_403("access refused") success, details = workspacesmanager.del_workspace(name=name) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "project successfully removed"}
def put(self, item_path): """update item""" user_profile = get_user(request=self.request) workspace = self.request.args.get("workspace", "common") item_path = fix_encoding_uri_param(item_path) success, details = actionstorage.instance().duplicate(item_path=item_path, workspace=workspace, user=user_profile) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": details}
def post(self): """add globals entries""" workspace = self.request.args.get("workspace", "common") # checking query request var_value = self.request.data.get("value") if var_value is None: raise HTTP_400("Value is expected") success, details = globalsmanager.saves_entries(content=var_value, workspace=workspace) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "success",}
def patch(self, item_path): """update item""" user_profile = get_user(request=self.request) workspace = self.request.args.get("workspace", "common") item_path = fix_encoding_uri_param(item_path) new_name = self.request.data.get("name") success, details = snippetstorage.instance().update(item_path=item_path, workspace=workspace, user=user_profile, new_name=new_name) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": details}
def post(self, item_path): """add script""" user_profile = get_user(request=self.request) workspace = self.request.args.get("workspace", "common") item_path = fix_encoding_uri_param(item_path) content_file = self.request.data.get("content", "") success, details = snippetstorage.instance().add(item_path=item_path, workspace=workspace, user=user_profile, content_file=content_file) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": details}
def delete(self, login): """delete user""" user_profile = get_user(request=self.request) if user_profile['role'] != constant.ROLE_ADMIN: raise HTTP_403("access refused") login = fix_encoding_uri_param(login) if user_profile["login"] == login: raise HTTP_403("deletion not authorized") success, details = usersmanager.delete_user(login=login) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "user successfully removed"}
def get(self, filename=None): """return snippets listing according to the project-id or read a specific script""" user_profile = get_user(request=self.request) workspace = self.request.args.get("workspace", "common") if filename is None: success, details = snippetstorage.instance().get_files(workspace=workspace, user=user_profile) else: filename = fix_encoding_uri_param(filename) success, details = snippetstorage.instance().read_file(filename=filename, workspace=workspace, user=user_profile) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "snippets": details}
def patch(self, login): """update user""" user_profile = get_user(request=self.request) # checking level access to this ressource if user_profile['role'] != constant.ROLE_ADMIN: raise HTTP_403("access refused") # checking query request login = fix_encoding_uri_param(login) role = self.request.data.get("role") if role not in constant.ROLE_LIST: raise HTTP_400("bad role provided") success, details = usersmanager.update_role(login=login, role=role) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "role successfully updated"}
def post(self): """Add a new project, only for administrator""" user_profile = get_user(request=self.request) # checking level access to this ressource if user_profile['role'] != constant.ROLE_ADMIN: raise HTTP_403("access refused") # checking request name = self.request.data.get("name") if name is None: raise HTTP_400("workspace name is mandatory") if not len(name): raise HTTP_400("workspace name cannot be empty") success, details = workspacesmanager.add_workspace(name=name) if success != constant.OK: raise HTTP_500(details) return {"cmd": self.request.path, "message": "workspace successfully added", "project-id": details}
def delete(self, file_path): """delete file""" user_profile = _get_user(request=self.request) if user_profile['monitor']: raise HTTP_403("Access refused") try: projectId = self.request.args.get("workspace", 1) file_path = fix_encoding_uri_param(file_path) except Exception as e: raise HTTP_400("Invalid request provided (%s ?)" % e) # avoid directory traversal filePath = os.path.normpath("/" + file_path) success = RepoTests.instance().delFile(pathFile=filePath, project=projectId, supportSnapshot=False) if success != Context.instance().CODE_OK: raise HTTP_500("Unable to delete file") return {"cmd": self.request.path, "message": "success"}
def _final_stage(self, code): client_id = config.get('vk', 'client_id') client_secret = config.get('vk', 'client_secret') vksession = Session() try: resp = vksession.get( 'https://oauth.vk.com/access_token?' 'redirect_uri=https://api.vk.com/blank.html' f'&client_id={client_id}&client_secret={client_secret}&code={code}' ) resp.raise_for_status() auth = resp.json() if not auth.get('access_token'): raise VKException(auth) resp = vksession.get('https://api.vk.com/method/users.get', params={ 'v': '5.92', 'user_ids': auth['user_id'], 'fields': 'photo_100', 'access_token': auth['access_token'] }) resp.raise_for_status() user = resp.json() if user.get('error'): raise VKException(user) user = user.get('response', {}) user = { 'id': user[0]['id'], 'fullname':\ (user[0].get('first_name', '') + ' ' + user[0].get('last_name', '')).strip(), 'photo': user[0].get('photo_100'), 'access_token': auth['access_token'] } if user else {} rpc_call('set_vk_user', user) token = jwt_auth.create_token({ 'id': auth['user_id'], 'aud': 'authorized' }) self.logger.info('Issued JWT: %s', token) return { 'token': 'Bearer ' + token.decode("utf-8"), 'tgauth': user.get('id') and rpc_call('is_tg_authorized', user['id']) } except exceptions.HTTPError as e: self.logger.info('Error authorizing user on VK: %s', e) if e.response.status_code == 401: raise HTTP_403('Error authorizing user on VK') raise HTTPError(e.response.status_code, e.response.text) except VKException as e: self.logger.warning('Error authorizing user on VK: %s', e) raise HTTP_403(e.message, e.code) except Exception as e: self.logger.exception('Error authorizing user on VK: %s', e) finally: vksession.close() raise HTTP_500('Internal error')
def post(self): """create job""" user_profile = _get_user(request=self.request) projectId = self.request.args.get("workspace", 1) try: yamlFile = self.request.data.get("yaml-file") if yamlFile is None: raise EmptyValue("Please specify a yaml file") yamlContent = self.request.data.get("yaml-content", "") scheduleId = self.request.data.get("schedule-id", 0) _scheduleAt = self.request.data.get("schedule-at") _scheduleRepeat = self.request.data.get("schedule-repeat", 0) _debugEnabled = self.request.data.get("debug-enabled") _fromTime = self.request.data.get("from-time") _toTime = self.request.data.get("to-time") _testInputs = self.request.data.get("file-parameters") projectId = int(projectId) scheduleId = int(scheduleId) except EmptyValue as e: raise HTTP_400("%s" % e) except Exception as e: raise HTTP_400("Invalid request provided (%s ?)" % e) # checking input if _testInputs is not None: if not isinstance(_testInputs, list): raise HTTP_400( "Invalid parameters provided in request, list expected") for inp in _testInputs: if not isinstance(inp, dict): raise HTTP_400( "Invalid parameters provided in request, list of dict expected") if not ("name" in inp and "type" in inp and "value" in inp): raise HTTP_400( "Invalid parameters provided in request") # run a test not save; change the project id to the default if projectId == 0: projectId = ProjectsManager.instance().getDefaultProjectForUser( user=user_profile['login']) _check_project_permissions( user_login=user_profile['login'], project_id=projectId) try: if yamlFile.startswith("//"): yamlFile = yamlFile[1:] yamlFile = os.path.normpath(yamlFile) p = pathlib.Path(yamlFile) fileExtension = p.suffix[1:] fileName = p.stem filePath = yamlFile.rsplit("%s%s" %(p.stem, p.suffix))[0] except Exception as e: raise HTTP_403('Invalid yaml file: %s' % e) if len(yamlContent): try: res = yaml.safe_load(yamlContent) except Exception as e: raise HTTP_403('Invalid yaml content: %s' % e) else: try: file_path = "%s/%s/%s/%s.%s" % (RepoTests.instance().testsPath, projectId, filePath, fileName, fileExtension) # read the file with open(file_path, "r") as f: doc_yaml = f.read() res = yaml.safe_load(doc_yaml) except Exception as e: raise HTTP_403('Invalid yaml file: %s' % e) try: # just for backward compatibility if "testplan" in res: testextension = "tpx" testfile = res["testplan"] elif "testglobal" in res: testextension = "tgx" testfile = res["testglobal"] elif "testsuite" in res: testextension = "tsx" elif "testunit" in res: testextension = "tux" # end of backward compatibility elif "python" in res: testextension = "tsx" elif "actions" in res: testextension = "tpx" testfile = res["actions"] else: raise Exception("invalid yaml format") # add default props if missing if "properties" not in res: res["properties"] = {} # add default descriptions if missing if "descriptions" not in res["properties"]: res["properties"]["descriptions"] = {} if "author" not in res["properties"]["descriptions"]: res["properties"]["descriptions"]["author"] = "undefined" if "name" not in res["properties"]["descriptions"]: res["properties"]["descriptions"]["name"] = "undefined" if "requirement" not in res["properties"]["descriptions"]: res["properties"]["descriptions"]["requirement"] = "undefined" if "summary" not in res["properties"]["descriptions"]: res["properties"]["descriptions"]["summary"] = "undefined" # add parameters if missing if "parameters" not in res["properties"]: res["properties"]["parameters"] = [] # add default scope in main parameters for p in res["properties"]["parameters"]: if "scope" not in p: p["scope"] = "local" if "value" not in p: p["value"] = "" if "type" not in p: if p["value"] is None: p["type"] = "none" p["value"] = "" elif isinstance(p["value"], bool): p["type"] = "bool" p["value"] = "%s" % p["value"] elif isinstance(p["value"], int): p["type"] = "int" p["value"] = "%s" % p["value"] elif isinstance(p["value"], list) or isinstance(p["value"], dict): p["type"] = "json" p["value"] = json.dumps(p["value"]) else: p["type"] = "text" testprops = {} testprops["inputs-parameters"] = {} testprops["inputs-parameters"]["parameter"] = res["properties"]["parameters"] testprops["descriptions"] = {} testprops["descriptions"]["description"] = [] for k,v in res["properties"]["descriptions"].items(): s = { 'key': k, 'value': v } testprops["descriptions"]["description"].append(s) if testextension in ["tpx", "tgx"]: doc = TestPlan.DataModel() testplan = {} testplan['testplan'] = { 'testfile': [] } i = 1 for tp in testfile: # add parameters if missing if "parameters" not in tp: tp["parameters"] = [] # add default scope in main parameters for p in tp["parameters"]: if "scope" not in p: p["scope"] = "local" if "value" not in p: p["value"] = "" if "type" not in p: if p["value"] is None: p["type"] = "none" p["value"] = "" elif isinstance(p["value"], bool): p["type"] = "bool" p["value"] = "%s" % p["value"] elif isinstance(p["value"], int): p["type"] = "int" p["value"] = "%s" % p["value"] elif isinstance(p["value"], list) or isinstance(p["value"], dict): p["type"] = "json" p["value"] = json.dumps(p["value"]) else: p["type"] = "text" if "id" not in tp: tp["id"] = "%s" % i if isinstance(tp["id"], int): tp["id"] = str(tp["id"]) if "parent" not in tp: tp["parent"] = "0" if isinstance(tp["parent"], int): tp["parent"] = str(tp["parent"]) if "parent-condition" not in tp: tp["parent-condition"] = "0" else: if tp["parent-condition"] == "success": tp["parent-condition"] = "0" else: tp["parent-condition"] = "1" tp["parent-condition"] = str(tp["parent-condition"]) if "description" in tp: tp["alias"] = tp["description"] i+=1 tf_descr = [ {"key": "author", "value": "undefined"}, {"key": "summary", "value": "undefined"}, {"key": "name", "value": "undefined"}, {"key": "requirement", "value": "undefined"}] tf_prop = {"properties": {"descriptions": { "description": tf_descr}, "inputs-parameters": {} }} tf_prop["properties"]["inputs-parameters"]["parameter"] = tp["parameters"] tp.update(tf_prop) testplan['testplan']['testfile'].append(tp) doc.testplan = testplan tests = doc.getSorted() if testextension == "tpx": success, error_msg = RepoTests.instance().addtf2tp(data_=tests) if success != Context.instance().CODE_OK: raise HTTP_500( 'Unable to prepare test plan: %s' % error_msg) else: success, error_msg, tests = RepoTests.instance().addtf2tg(data_=tests) if success != Context.instance().CODE_OK: raise HTTP_500( 'Unable to prepare test global: %s' % error_msg) testData = {'test-properties': testprops, 'test-extension': testextension} if testextension == "tsx": if "python" in res: testData['test-definition'] = res["python"] else: testData['test-definition'] = res["testsuite"] testData['test-execution'] = "" elif testextension == "tux": testData['test-definition'] = res["testunit"] else: testData['test-execution'] = tests except Exception as e: raise HTTP_500('Unable to decode yaml: %s' % e) # now we can create the task debugEnabled = False fromTime = (0, 0, 0, 0, 0, 0) toTime = (0, 0, 0, 0, 0, 0) message = "success" scheduleAt = (0, 0, 0, 0, 0, 0) if _debugEnabled is not None: debugEnabled = _debugEnabled if _fromTime is not None: fromTime = _fromTime if _toTime is not None: toTime = _toTime if _scheduleAt is not None: scheduleAt = _scheduleAt # personalize test description ? if _testInputs is not None: for newInp in _testInputs: if "scope" not in newInp: newInp["scope"] = "local" for origInp in testData["test-properties"]['inputs-parameters']['parameter']: if "scope" not in origInp: origInp["scope"] = "local" # if the param exist on the original test than overwrite # them if newInp["name"] == origInp["name"]: origInp["value"] = newInp["value"] origInp["type"] = newInp["type"] origInp["scope"] = newInp["scope"] if not filePath.endswith(fileName): if len(filePath): _testPath = "%s/%s" % (filePath, fileName) else: _testPath = fileName _testPath = os.path.normpath(_testPath) else: _testPath = filePath task = TaskManager.instance().registerTask( testData=testData, testName=fileName, testPath=_testPath, testUserId=user_profile['id'], testUser=user_profile['login'], testId=0, testBackground=True, runAt=scheduleAt, runType=scheduleId, runNb=_scheduleRepeat, withoutProbes=False, debugActivated=debugEnabled, withoutNotif=False, noKeepTr=False, testProjectId=projectId, runFrom=fromTime, runTo=toTime, stepByStep=False, breakpoint=False, channelId=False ) if task.lastError is not None: raise HTTP_500('ERROR: %s' % task.lastError) message = "success" if task.isRecursive(): message = "recursive" if task.isPostponed(): message = "postponed" if task.isSuccessive(): message = "successive" return {"cmd": self.request.path, "message": message, "job-id": task.getId(), "execution-id": task.getTestID()}
def post(self): phone = parse_phone(self.request.data.get('phone')) if phone == self.user['phone_number']: user = self.get() if user.get('authorized', True): return user code = self.request.data.get('code') password = self.request.data.get('password') phone_code_hash = None if not phone: raise HTTP_400('Invalid `phone` value') msg = None is_authorized = False try: client = TelegramClient( os.path.join(config.get('paths', 'sessions'), parse_phone(phone)), config.get('telegram', 'api_id'), config.get('telegram', 'api_hash')) if not client.is_connected(): client.connect() # check if already authorized if client.is_user_authorized(): self._set_authorized(phone) is_authorized = True raise AuthorizedSuccessfully() # 2nd step if code: t = db.get_interim_state(phone) if not t: raise HTTP_400('Invalid `phone` value') phone_code_hash = t['phone_code_hash'] resp = client.sign_in(phone, code, password=password, phone_code_hash=phone_code_hash) # 2nd/3rd step success if code and client.is_user_authorized(): self._set_authorized(phone) is_authorized = True raise AuthorizedSuccessfully() # 1st step if not resp.phone_registered: db.del_interim_state(phone) raise HTTP_400('Phone number is not registered') db.set_interim_state(phone, { 'provider': 'Telegram', 'phone_code_hash': resp.phone_code_hash }) return {'authorized': False, 'code': True} except AuthorizedSuccessfully: pass except SessionPasswordNeededError: return {'authorized': False, '2fa': True} except (PhoneNumberBannedError, PhoneNumberInvalidError, PhoneCodeExpiredError, PhoneCodeInvalidError, PhoneCodeEmptyError, PhonePasswordProtectedError) as e: db.del_interim_state(phone) client.log_out() raise HTTP_400(str(e)) except (FloodWaitError, FloodError, PhonePasswordFloodError) as e: db.del_interim_state(phone) raise HTTP_400(str(e)) except HTTPError: # passthru raise except Exception as e: self.logger.error('Telegram communication error %s', e) msg = str(e) raise finally: client.disconnect() if is_authorized: return self.get() raise HTTP_500('Internal error', msg)