Ejemplo n.º 1
0
    def GET(self, *paths, **params):

        if validate(cherrypy.request.headers):

            try:
                try:
                    reqid = get_parameters(params, "reqid")[0]
                except KeyError:
                    return handle_error(400, "Bad Request")

                fname = os.path.join("results", reqid + ".zip")
                with open(fname, "rb") as archive:
                    response = archive.read()

                # set response header for zip
                ctype = "application/zip"
                cherrypy.response.headers["Content-Type"] = ctype
                cdisp = 'attachment; filename="' + reqid + '.zip"'
                cherrypy.response.headers["Content-Disposition"] = cdisp

                return response
            except:
                return handle_error(500, "Internal Server Error")
        else:
            return handle_error(401, "Unauthorized")
Ejemplo n.º 2
0
Archivo: rest.py Proyecto: fbrundu/dimc
    def GET(self, **params):

        if validate(cherrypy.request.headers):
            try:
                return handle_error(200, "Pong")
            except:
                return handle_error(500, "Internal Server Error")
        else:
            return handle_error(401, "Unauthorized")
Ejemplo n.º 3
0
    def GET(self):

        if validate(cp.request.headers, self.cas_server, self.serviceID):
            try:
                return handle_error(200, "Pong")
            except:
                return handle_error(500, "Internal Server Error")
        else:
            return handle_error(401, "Unauthorized")
Ejemplo n.º 4
0
Archivo: rest.py Proyecto: fbrundu/dimc
    def GET(self, **params):

        if validate(cherrypy.request.headers):
            try:
                # basic ping response through the infrastructure
                r = requests.get(urllib.parse.urljoin(bimprovider_url, "ping"))

                # return response
                return handle_error(200, r.json()["message"] + "thru")
            except:
                return handle_error(500, "Internal Server Error")
        else:
            return handle_error(401, "Unauthorized")
Ejemplo n.º 5
0
Archivo: rest.py Proyecto: fbrundu/bimp
    def GET(self, *paths, **params):

        try:
            # do query on buildings' database
            result, qdesc, qparams, internal_log = db.query(params, pbc)

            if internal_log:
                log.error(msg=internal_log, context='HTTP')

            # create response
            response = {
                "r_ver": QUERY_VERSION,
                "q_ts": datetime.datetime.now().isoformat(),
                "q_desc": qdesc,
                "q_par": qparams,
                "q_res": result
            }

            # result to json
            response = json.dumps(response).encode("utf8")
            ctype = "application/json;charset=utf-8"
            cherrypy.response.headers["Content-Type"] = ctype

            # return response
            return response
        except:
            return handle_error(500, "Internal Server Error")
Ejemplo n.º 6
0
Archivo: rest.py Proyecto: fbrundu/dimc
    def GET(self, *paths, **params):

        if validate(cherrypy.request.headers):
            try:
                # query
                url = urllib.parse.urljoin(bimprovider_url, "query")
                response = query(url, params)
                ctype = "application/json;charset=utf-8"
                cherrypy.response.headers["Content-Type"] = ctype

                # return response
                return response
            except:
                return handle_error(500, "Internal Server Error")
        else:
            return handle_error(401, "Unauthorized")
Ejemplo n.º 7
0
Archivo: rest.py Proyecto: fbrundu/dimc
    def GET(self, *paths, **params):

        if validate(cherrypy.request.headers):
            try:
                # get zip of ifcs
                url = urllib.parse.urljoin(bimprovider_url, "getifc")
                response = get_resources(url, params)

                # set response header for zip
                cherrypy.response.headers["Content-Type"] = "application/zip"
                cdisp = 'attachment; filename="resp.zip"'
                cherrypy.response.headers["Content-Disposition"] = cdisp

                return response
            except:
                return handle_error(500, "Internal Server Error")
        else:
            return handle_error(401, "Unauthorized")
Ejemplo n.º 8
0
Archivo: rest.py Proyecto: fbrundu/bimp
    def GET(self, *paths, **params):

        try:
            # get zip of gbxmls
            response = get_resources(params, "fbx")

            # set response header for zip
            cherrypy.response.headers["Content-Type"] = "application/zip"
            cdisp = 'attachment; filename="resp.zip"'
            cherrypy.response.headers["Content-Disposition"] = cdisp

            return response
        except:
            return handle_error(500, "Internal Server Error")
Ejemplo n.º 9
0
    def POST(self, *paths, **params):

        if validate(cherrypy.request.headers):

            try:
                reqid = str(uuid.uuid4())
                try:
                    subnets = get_parameters(params, "subnets")
                except KeyError:
                    return handle_error(400, "Bad Request")
                respath = os.path.abspath("results")
                srcpath = os.path.abspath("mlab")
                os.makedirs(os.path.join(respath, reqid))
                wargs = [(self.mlab_path, reqid, respath, srcpath, subnets)]
                self.pool.apply_async(Peak.worker,
                                      wargs,
                                      callback=self.publish)

                return handle_error(202, "Request ID: " + reqid)
            except:
                return handle_error(500, "Internal Server Error")
        else:
            return handle_error(401, "Unauthorized")
Ejemplo n.º 10
0
Archivo: rest.py Proyecto: fbrundu/bimp
    def GET(self, *paths, **params):

        try:
            # get buildings as JSON array
            result, internal_log = get_json(params)

            if internal_log:
                log.error(msg=internal_log, context='HTTP')

            # result to json
            response = json.dumps(result, indent=2).encode("utf8")

            # return response
            ctype = "application/json;charset=utf-8"
            cherrypy.response.headers["Content-Type"] = ctype

            return response
        except:
            return handle_error(500, "Internal Server Error")
Ejemplo n.º 11
0
Archivo: rest.py Proyecto: fbrundu/bimp
    def GET(self, **params):

        try:
            return handle_error(200, "Pong")
        except:
            return handle_error(500, "Internal Server Error")