예제 #1
0
    def post(self):
        e = Entity()
        if not request.is_json:
            e.status = Status.FAILED
            e.data = {"MESSAGE": "Missing JSON request body"}
            return e.to_dict(), 400
        usr = request.json.get("USERNAME", None)
        pwd = request.json.get("PASSWORD", None)
        if usr is None or pwd is None:
            e.status = Status.FAILED
            e.data = {
                "MESSAGE": "Missing one of the login parameters",
                "USERNAME": usr,
                "PASSWORD": pwd
            }
            return e.to_dict(), 400
        else:
            for u in USERS:
                if u.get("USERNAME") == usr and u.get("PASSWORD") == pwd:
                    token = create_access_token(identity=usr)
                    e.status = Status.SUCCESS
                    e.data = {"TOKEN": token}
                    break
            else:
                e.status = Status.SUCCESS
                e.data = {"MESSAGE": "User is not authorized to access API"}

        return e.to_dict(), 200
예제 #2
0
 def get(self):
     r = dict()
     r["/help"] = "[GET] Lists all available API calls to the generator"
     r["/car-sim"] = "Car simulator API"
     r["/car-sim/generate"] = "[POST] Call to generate Car Simulator game"
     e = Entity(status=Status.SUCCESS, data=r)
     return e.to_dict()
예제 #3
0
    def get(self):
        """Description: Helper GET call to list all Python specific API calls in Generator

        :return: Dictionary with path and description values
        """
        r = dict()
        r["/api/python"] = "GET: General API information containing python specific calls"
        r["/api/python/generate"] = "POST: Python code generator from blueprint json strings"
        e = Entity(status=Status.SUCCESS, data=r)
        return e.to_dict()
예제 #4
0
    def get(self, name):
        """Description: GET generate python project from registered project

        :param name: Project name to generate from
        :return: Entity object with request status
        """
        p = ProjectManager.get_project(name)
        e = Entity()
        if p is not None:
            e.status = PythonGenerator.generate(p)
        else:
            e.status = Status.GENERATION_FAILED
        return e.to_dict()
예제 #5
0
    def post(self):
        """Description: POST register project

        :return: Registration status
        """
        e = Entity()
        if isinstance(flask_restful.request.get_json(), str):
            data = json.loads(flask_restful.request.get_json())
        elif isinstance(flask_restful.request.get_json(), dict):
            data = flask_restful.request.get_json()
        else:
            data = dict()
        p = ProjectManager.create_project(data)
        e.status = ProjectManager.add_project(p)
        return e.to_dict()
예제 #6
0
    def put(self, name):
        """Description: PUT updates project and it`s content

        :param name: Project name
        :return: Request status
        """
        e = Entity()
        p = ProjectManager.get_project(name)
        if isinstance(flask_restful.request.get_json(), str):
            data = json.loads(flask_restful.request.get_json())
        elif isinstance(flask_restful.request.get_json(), dict):
            data = flask_restful.request.get_json()
        else:
            data = dict()
        e.status = ProjectManager.update_project(p, data)
        return e.to_dict()
예제 #7
0
    def get(self, name=None):
        """Description: GET single project by name or all registered projects

        :param name: <<Optional>> project name
        :return: Project JSON response
        """
        if name is None:
            r = list()
            for p in ProjectManager.PROJECTS:
                r.append(p.to_dict())
        else:
            r = ProjectManager.get_project(name)
            r = r.to_dict()

        e = Entity(status=Status.SUCCESS, data=r)
        return e.to_dict()