Exemplo n.º 1
0
    def decorator(*args, **kwargs):
        p.pprint(__user_id)
        print(" => Login ", end='')

        if (request.content_type == "application/json"):
            print(" => JSON ", end='')
            dictionary = request.get_json()
            if "key" in dictionary:
                print(" => key {}".format(dictionary["key"]), end='')
                key = __verify_key(dictionary["key"])
                if key:
                    print(" => key is verified ", end='')
                    return f(key)
                else:
                    return JSONError(300, "key does not exist")

            if "login" in dictionary and "password" in dictionary:
                print(dictionary["login"], dictionary["password"], end='')
                key = __verify_login(dictionary["login"],
                                     dictionary["password"])
                if (key):
                    print(" => key is verified {} ".format(key), end='')
                    return JSONKey(key)
                else:
                    return JSONError(300, "wrong login or password")

            return JSONError(0, "API ERROR " + __name__)

        else:
            print(" => HTML", end='')

            if ("key" in request.cookies.keys()):
                print(" => cookies [{}]".format(request.cookies.get("key")),
                      end='')
                key = __verify_key(request.cookies.get("key"))
                print(key)
                if key:
                    print(" => key is verified", end='')
                    return f(key=key, *args, **kwargs)

            if ("login" in request.form.keys()
                    and "password" in request.form.keys()):
                print(" => post form login ", end='')
                print("FORM LOGIN: "******"login"),
                      " PASSWORD: "******"password"))
                key = __verify_login(request.form.get("login"),
                                     request.form.get("password"))
                print(key)
                if (key):
                    print(" => login is verified", end='')
                    return f(key=key, *args, **kwargs)
        return f(key=None)
Exemplo n.º 2
0
def getHTMLResponce(request_data: dict):
    function = request_data["function"]
    if ("id" in request_data):
        if (None == __Container_Controller.get(request_data["id"])):
            return JSONError(500, "container not found")
        if (function == "start"):
            __Container_Controller.start_container(request_data["id"])
        if (function == "stop"):
            __Container_Controller.stop_container(request_data["id"])
        if (function == "remove"):
            __Container_Controller.delete(request_data["id"])
    if ("type" in request_data):
        if (function == "startall"):
            __Container_Controller.start_all_containers()
        if (function == "stopall"):
            __Container_Controller.stop_all_containers()
        if (function == "removeall"):
            __Container_Controller.remove_all_containers()
    Containers = __Container_Controller.list()
    print(Containers)
    if (len(Containers) == 0):
        return "Empty containers list"
    s = DICTContainers(Containers)
    resp = make_response(
        render_template("container_table_template.html", containers=s))
    return resp
Exemplo n.º 3
0
def getJsonResponce(request_data: dict):
    function = request_data["function"]
    if ("image" in request_data):
        tag = request_data["tag"] if ("tag" in request_data) else "latest"
        imagename = request_data["image"] if ":" in request_data[
            "image"] else "{}:{}".format(request_data["image"], tag)
        if (function == "pull"):
            if request_data["tag"] == "all":
                tag = None
            return JSONSuccess() if __Image_Controller.pull(
                request_data["image"], tag=tag) else JSONError(
                    500, "Image Pull Crash")
        if (function == "delete"):
            return JSONSuccess() if __Image_Controller.delete(
                imagename) else JSONError(500, "Image Pull Crash")
        if (function == "get"):
            Image = __Image_Controller.getByName(imagename)
            if (Image):
                return JSONImageTemplateByImage(Image)
            else:
                return JSONError(
                    500,
                    "image '{}' not been found. ot found image or specyfic image Tag"
                    .format(imagename))
        if (function == "run"):
            Container = __Image_Controller.run(imagename)
            if (Container):
                return JSONContainers([Container])
            else:
                return JSONError(500, "you can not run that container")
        return JSONError(1, "None defined function")
    if ("type" in request_data):
        if (function not in ["deleteall", "list"]):
            return JSONError(
                500,
                "function '{}' is not defined in SCM API".format(function))
        if (function == "deleteall"):
            return JSONSuccess() if __Image_Controller.delete_all(
            ) else JSONMessage([("describe", "force delete is crashed")])
        if (function == "deleteall"):
            return JSONSuccess() if __Image_Controller.prune(
            ) else JSONMessage([("describe",
                                 "not available containers, or api error")])
        if (function == "list"):
            Images = __Image_Controller.list()
            if (Images):
                return JSONImages(Images)
            else:
                return JSONMessage([("images", "[]")])
    return JSONError(0, "None defined exception")
Exemplo n.º 4
0
def getJsonResponce(request_data: dict):
    function = request_data["function"]
    if ("id" in request_data):
        if (None == __Container_Controller.get(request_data["id"])):
            return JSONError(500, "container not found")
        if (function == "start"):
            return JSONSuccess() if __Container_Controller.start_container(
                request_data["id"]) else JSONError(500, "container stop error")
        if (function == "stop"):
            return JSONSuccess() if __Container_Controller.stop_container(
                request_data["id"]) else JSONError(500, "container stop error")
        if (function == "remove"):
            return JSONSuccess() if __Container_Controller.delete(
                request_data["id"]) else JSONError(500,
                                                   "Container remove error ")
        if (function == "info"):
            Container = __Container_Controller.get(request_data["id"])
            if (Container):
                return JSONContainers([Container])
            else:
                return JSONError(500, "bad container ID")
        return JSONError(1, "None defined function")
    if ("type" in request_data):
        if (function == "startall"):
            return JSONSuccess(
            ) if __Container_Controller.start_all_containers() else JSONError(
                500, "containers stop error")
        if (function == "stopall"):
            return JSONSuccess() if __Container_Controller.stop_all_containers(
            ) else JSONError(500, "containers stop error")
        if (function == "removeall"):
            return JSONSuccess(
            ) if __Container_Controller.remove_all_containers() else JSONError(
                500, "Containers remove error ")
        if (function == "list"):
            Containers = __Container_Controller.list()
            print(Containers)
            if (len(Containers) > 0):
                return JSONContainers(Containers)
            elif len(Containers) == 0:
                return JSONMessage([("containers", "[]")])
            else:
                return JSONError(500, "Container API crash")
    return JSONError(0, "None defined request")
Exemplo n.º 5
0
def __authentifiation__service__error():
    resp = Response(JSONError(500, "internal server error"))
    resp.content_type = "application/json"
    FlaskSerwer.process_response(resp)
    return resp
Exemplo n.º 6
0
def __error401_NotVarifyAccess():
    resp = Response(JSONError(401, "Not verified access to resource"))
    resp.content_type = "application/json"
    FlaskSerwer.process_response(resp)
    return resp
Exemplo n.º 7
0
def logoutJSON(key):
    if(key != None):
        clean_key(key)
        return JSONLogoutSuccess()
    return JSONError(500, "not found user")