Ejemplo n.º 1
0
    def post(self, *args, **kwargs):
        argObj = getArgObj(self.request)

        # import time
        # yield tornado.gen.Task(tornado.ioloop.IOLoop.instance().add_timeout, time.time() + 10)

        if (not argObj.get("api")):
            ERROR("not a valid api, no api exist")
            self.write(buildFailureReply(INVALID_PARAS))
            self.finish()
            return

        (status, session) = self.checkSession(argObj)
        if (not status):
            ERROR("check session failed %s " % str(argObj))
            self.write(buildFailureReply(NO_AUTH_SKEY))
            self.finish()
            return

        (role, accountId) = self.getAccountInfo(session)
        argObj["paras"]["role"] = role

        # IF accountId Specified, just use it
        if not argObj["paras"].get("accountId"):
            argObj["paras"]["accountId"] = accountId

        if argObj["api"].split(".")[-1] == "APILogOut":
            argObj["centerSessionID"] = self.get_cookie("centerSessionID",
                                                        "").replace("%22", "")
            DEBUG(argObj)

        retObj = doDispatching(argObj, session, API_PROTOS)
        self.write(buildReply(retObj))
        self.finish()
Ejemplo n.º 2
0
    def post(self):

        # Step 1, Login with default account
        argObj = getArgObj(self.request)
        paras = {
            "account": self.get_argument("username"),
            "password": self.get_argument("password"),
            "role": 7,
        }
        argObj["api"] = "octlink.tundra.v1.account.APILoginByAccount"
        argObj["paras"] = paras

        self.db = dbmysql.mysqldb()
        session = getSessionObj(self.db,
                                sessionId="00000000000000000000000000000000")
        del self.db

        argObj["session"] = session
        retObj = doDispatching(argObj, session, API_PROTOS)
        if retObj["RetCode"] != OCT_SUCCESS:
            ERROR("login error %s" % str(retObj))
            self.redirect("/login/?error=true")
        else:
            sessionObj = retObj["RetObj"]["session"]
            self.set_cookie("rvmusercookie", sessionObj["id"])
            self.set_cookie("username", retObj["RetObj"]["name"])
            self.set_cookie("userid", retObj["RetObj"]["id"])
            self.redirect("/")
Ejemplo n.º 3
0
    def post(self, *args, **kwargs):

        argObj = getArgObj(self.request)
        api = argObj["api"]
        paras = argObj["paras"]
        async = False

        if paras["timeout"] != 0:
            async = True

        api_body = {
            "api": api,
            "paras": paras,
            "async": async,
            "session": {
                "uuid": "00000000000000000000000000000000"
            }
        }

        self.result["paras"] = argObj["paras"]
        self.result["moduleSelected"] = argObj["module"]
        self.result["apiSelected"] = argObj["api"]
        self.result["request"] = json.dumps(argObj,
                                            indent=4,
                                            ensure_ascii=False)

        client = tornado.httpclient.AsyncHTTPClient()

        url = "http://%s:%d/api/" % ("127.0.0.1", RUNNING_PORT)
        ERROR("%sfff" % url)
        response = yield client.fetch(url,
                                      method="POST",
                                      request_timeout=10,
                                      connect_timeout=10,
                                      body=json.dumps(api_body))
        self.on_response(response)