def web_get_api(db, env, arg): apiId = arg["paras"].get('id') if not apiId: return buildRetObj(SEGMENT_NOT_EXIST, None) api = getApi(db, apiId) if (not api): return buildRetObj(SEGMENT_NOT_EXIST, None) return buildRetObj(OCT_SUCCESS, api.toObj())
def web_logout(db, env, arg): sessionId = arg.get("centerSessionID") if not sessionId: ERROR("no session uuid to logout %s" % str(arg)) return buildRetObj(OCT_SUCCESS) session = getSession(db, sessionId) if not session: ERROR("get session error to logout %s" % sessionId) return buildRetObj(OCT_SUCCESS) return buildRetObj(OCT_SUCCESS)
def web_login(db, env, arg): paras = arg["paras"] user = userService.getUserByName(db, paras.get("account")) if (not user): return buildRetObj(USER_NOT_EXIST, None) ret = user.auth(b64_decode(paras.get("password"))) if ret == 0: data = {"id": user.myId, "name": user.name, "role": user.role} sessionObj = newSession(db, data) data["session"] = sessionObj return buildRetObj(OCT_SUCCESS, data) else: return buildRetObj(USER_PASSWD_ERR)
def web_logout(db, env, arg): paras = arg["paras"] sessionId = paras.get("sessionUuid") removeSession(db, sessionId) return buildRetObj(OCT_SUCCESS)
def doServerDispatching(arg, API_LIST): apiProto = API_LIST.get(arg.get("api")) if (not apiProto): ERROR("func of %s not exist" % arg.get("api")) return buildRetObj(SEGMENT_NOT_EXIST) ret, errorMsg = checkParas(arg.get("paras"), apiProto) if (not ret): ERROR("check paras error [%s]" % errorMsg) return buildRetObj(INVALID_PARAS, errorLog=errorMsg) arg["async"] = False # TBD if (arg.get("async")): return writeServerApi(arg, apiProto) else: return callServerWebServiceDir(apiProto["func"], arg, apiProto)
def web_get_user(db, env, arg): userId = arg["paras"].get("id") if userId == None: ret, data = userService.get_alluser(db, arg) else: ret, data = userService.get_user(db, userId) return buildRetObj(ret, data)
def web_ukeylogin(db, env, arg): user = userService.getUserByUkey(db, str(arg["paras"].get("ukey"))) if (not user): return buildRetObj(USER_NOT_EXIST, None) ret = user.authUkey(arg["paras"].get("ukey")) if ret == 0: data = { 'id': user.uid, 'ukey': user.ukey, 'name': user.name, 'role': user.role } return buildRetObj(OCT_SUCCESS, data) elif ret == -2: return buildRetObj(USER_PASSWD_ERR) else: return buildRetObj(DB_ERR)
def doDispatching(arg, session, API_LIST): apiProto = API_LIST.get(arg.get("api")) if (not apiProto): ERROR("func of %s not exist" % arg.get("api")) return buildRetObj(SEGMENT_NOT_EXIST) ret, errorMsg = checkParas(arg.get("paras"), apiProto) if (not ret): ERROR("check paras error [%s]" % errorMsg) return buildRetObj(UNACCP_PARAS, errorLog=errorMsg) ret, errorMsg = checkRoles(arg.get("paras"), apiProto) if (not ret): ERROR("check roles error [%s]" % errorMsg) return buildRetObj(PERMISSION_NOT_ENOUGH, errorLog=errorMsg) arg["async"] = False # TBD if (arg.get("async")): return writeApi(arg, session, apiProto) else: return callWebServiceDir(apiProto["func"], session, arg, apiProto)
def post(self): try: file_metas = self.request.files["file"] except: file_metas = self.request.files["filename"] fileName = file_metas[0].get("filename") or "unknown" if isSystemWindows(): filePath = "var/tmp/" + fileName + ".XXXX" + getUuid() else: filePath = "/tmp/" + fileName + ".XXXX" + getUuid() for meta in file_metas: with open(filePath, 'wb') as up: up.write(meta['body']) retObj = buildRetObj(OCT_SUCCESS, data=filePath) self.write(buildReply(retObj)) self.finish()
def web_logout(db, env, arg): ret, data = robotService.logout_robot(db, arg) return buildRetObj(ret, data)
def web_update_robot(db, env, arg): ret = robotService.update_robot(db, arg) return buildRetObj(ret)
def web_add_robot(db, env, arg): ret = robotService.add_robot(db, env, arg) return buildRetObj(ret)
def web_del_robot(db, env, arg): ret = robotService.delete_robot(db, arg) return buildRetObj(ret)
def web_get_allrobot(db, env, arg): ret, data = robotService.get_allrobot(db, arg) return buildRetObj(ret, data)
def web_get_robotlist(db, env, arg): (ret, data) = robotService.get_robotlist(db, arg) return buildRetObj(ret, data)
def web_update_user(db, env, arg): ret = userService.update_user(db, arg) return buildRetObj(ret)
def web_get_userlist(db, env, arg): (ret, data) = userService.get_userlist(db) return buildRetObj(ret, data)
def web_remove_pricing(db, env, arg): ret, data = remove_pricing(db, arg["paras"]) return buildRetObj(ret, data)
def web_del_user(db, env, arg): ret = userService.delete_user(db, arg["paras"]["id"]) return buildRetObj(ret)
def web_delete_api(db, env, arg): ret = deleteApi(db, arg) return buildRetObj(ret, None)
def web_del_user(db, env, arg): ret = userService.delete_user(db, arg) return buildRetObj(ret)
def web_add_user(db, env, arg): ret = userService.add_user(db, arg) return buildRetObj(ret)
def web_get_robot(db, env, arg): ret, data = robotService.get_robot(db, arg["paras"]["id"]) return buildRetObj(ret, data)
def web_get_product_types(db, env, arg): ret, data = get_product_types(db, arg["paras"]) return buildRetObj(ret, data)
def web_add_apiresult(db, env, arg, result=None): (ret, data) = addApiResult(db, env, arg, result) return buildRetObj(ret, data)
return 0, None def get_server_key(): return API_TEST_KEY def api_call_server(address, paras, api_proto, port=SERVER_PORT, async=False, https=False): (ret, errorLog) = parse_paras(paras, api_proto) if (ret): retObj = buildRetObj(ret, data=None, errorLog=errorLog) return ApiResponse(ret, retObj) (ret, resp) = api_call(address, port, api_proto["apikey"], paras, get_server_key(), async, server=True, https=https) return ApiResponse(ret, resp) def api_call_vr(address, paras, api_proto,
def web_add_api(db, env, arg): paras = arg["paras"] (ret, data) = addApi(db, arg, paras) return buildRetObj(ret, data)
def web_modify_password(db, env, arg): ret = userService.change_password(db, arg) return buildRetObj(ret)
def web_get_apis(db, env, arg): ret, data = getApis(db, arg) return buildRetObj(ret, data)
def web_reset_password(db, env, arg): ret = userService.reset_password(db, arg) return buildRetObj(ret)