Ejemplo n.º 1
0
def pre_ship():
    try:
        routeRequestLogger.info(request)
        return render_template("index.html")
    except:
        routeRequestLogger.exception(request)
        return jsonify(**{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 2
0
def favicon():
    try: 
        routeRequestLogger.info(request)
        return send_from_directory(os.path.join(app.root_path, 'static'), 'output.ico',mimetype='image/vnd.microsoft.icon')
    except:
        routeRequestLogger.exception(request)
        return jsonify(**{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 3
0
def showObjectRoutes():
    try:
        data = request.get_json()

        routeObject = getRoute(data['userId'], {'id': data['objectId']})
        if not routeObject:
            return jsonify(
                **{'message': 'List of Objects not found'}), ErrorCode_NotFound

        routeRequestLogger.info(request)

        if not checkParam(data, 'userId') or \
                not checkParam(data, 'objectId'):
            return jsonify(**{'message': 'Bad params'}), ErrorCode_BadParams

        routeObject = getRoute(data['userId'], {'id': data['objectId']})
        if not routeObject:
            return jsonify(
                **{'message': 'Object not found'}), ErrorCode_NotFound

        # stupid route creation code
        customRoutes = []
        for protocol in ['/create', '/read', '/update', '/delete']:
            customRoutes += [protocol + routeObject.objectName]

        # Now send the routes made by the builder
        return jsonify(**{'routes': customRoutes}), ErrorCode_Success
    except:
        routeRequestLogger.exception(request)
        return jsonify(
            **{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 4
0
def updateObjectAttribute():
    try:
        data = request.get_json()

        routeRequestLogger.info(request)

        if data is None:
            return jsonify(
                **{'message': 'No data found'}), ErrorCode_ServerError

        if not checkParam(data, 'userId') or not checkParam(data, 'attributeId') or not\
            checkParams(data['updatedObjectAttribute'], *ObjectAttributes.params):
            return jsonify(**{'message': 'Bad params'}), ErrorCode_BadParams

        user = retrieveUser(data['userId'])
        if user is None:
            return jsonify(
                **{'message': 'No data found'}), ErrorCode_ServerError
        if not isValidUser(user.id):
            return jsonify(**{'message': 'Bad Params'}), ErrorCode_BadParams

        if updateObjectAttributes(user.id, data['attributeId'],
                                  **data['updatedObjectAttribute']):
            return jsonify(
                **{'attributeId': data['attributeId']}), ErrorCode_Success

        return jsonify(**{'message': 'Update failed'}), ErrorCode_ServerError
    except:
        routeRequestLogger.exception(request)
        return jsonify(
            **{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 5
0
def addNewRouteGroup():
    try:
        data = request.get_json()

        routeRequestLogger.info(request)

        if not checkParams(data, *RouteGroup.params):
            generalLogger.error("data sent to " + request.path +
                                " does not have correct params. Expected " +
                                RouteGroup.params + " but received " + data)

            return jsonify(**{"message": "Bad params"}), ErrorCode_BadParams

        if data['objectName'] == '':
            generalLogger.error("route group name is empty. cannot be empty")
            return jsonify(**{"message": "Bad params"}), ErrorCode_BadParams

        user = retrieveUser(data['userId'])

        newRouteGroup = RouteGroup(data['userId'], data["objectName"],
                                   data["apiId"], data["isCRUD"],
                                   data['isReadMultiple'],
                                   data['isReadAllObjects'],
                                   data['isSingleRoute'])

        addRoute(user.id, newRouteGroup)
        return jsonify(**{"objectId": newRouteGroup.id}), ErrorCode_Success
    except:
        routeRequestLogger.exception(request)
        return jsonify(
            **{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 6
0
def deleteRouteGroup():
    try:
        data = request.get_json()

        routeRequestLogger.info(request)

        if data is None:
            return jsonify(
                **{'message': 'No data found'}), ErrorCode_ServerError

        if not checkParam(data, 'userId') or not checkParam(data, 'objectId'):
            return jsonify(**{'message': 'Bad params'}), ErrorCode_BadParams

        user = retrieveUser(data['userId'])
        if user is None:
            return jsonify(
                **{'message': 'No data found'}), ErrorCode_ServerError
        if not isValidUser(user.id):
            return jsonify(**{'message': 'Bad Params'}), ErrorCode_BadParams

        deleteRoute(user.id, data['objectId'])

        return jsonify(**{}), ErrorCode_Success
    except:
        routeRequestLogger.exception(request)
        return jsonify(
            **{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 7
0
def checkValidUser():
    try:
        data = request.get_json()

        routeRequestLogger.info(request)

        if not checkParam(data, 'userId'):
            return jsonify(**{'message': 'Bad params'}), ErrorCode_BadParams
        if not isValidUser(int(data['userId'])):
            return jsonify(**{'message': 'Invalid User'}), ErrorCode_NotFound
        return jsonify(**{'id': int(data['userId'])}), ErrorCode_Success
    except:
        routeRequestLogger.exception(request)
        return jsonify(**{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 8
0
def grabFakeUser():
    try:
        routeRequestLogger.info(request=request)
        
        newUser = gimmeNewUser()
        response_body = jsonify(**{'id': newUser.id})

        routeResponseLogger.info(
            request=request,
            response_body=json.dumps({'id': newUser.id}),
            status_code=ErrorCode_Success
        )    

        return response_body
    except:
        routeRequestLogger.exception(request)
        return jsonify(**{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 9
0
def addObjectAttribute():
    try:
        data = request.get_json()

        routeRequestLogger.info(request)

        if not checkParams(data, *['userId', 'objectId', 'attributes']):
            return jsonify(**{'message': 'Bad params'}), ErrorCode_BadParams

        attributeIds = []

        user = retrieveUser(data['userId'])
        route = getRoute(user.id, {"id": data['objectId']})
        for row in data['attributes']:
            if not checkParams(row, *ObjectAttributes.params):
                return jsonify(
                    **{'message': 'Bad params'}), ErrorCode_BadParams
            if row['name'] == '':
                return jsonify(
                    **{'message': 'Bad params'}), ErrorCode_BadParams

            routeRequestLogger.info(request_method=POST,
                                    url=request.path,
                                    request_body=data,
                                    client_ip=request.remote_addr)

            if not checkParams(data, *['userId', 'objectId', 'attributes']):
                return jsonify(
                    **{'message': 'Bad params'}), ErrorCode_BadParams

            newObjectAttributes = ObjectAttributes(
                data['userId'], data['objectId'], row['name'], row['type'],
                row['description'], row['isUnique'], row['isEncrypted'],
                row['isNullable'], row['generationMethod'])
            addObjectAttributes(user.id, route.id, newObjectAttributes)

            attributeIds += [newObjectAttributes.id]

        return jsonify(**{'attributeIds': attributeIds}), ErrorCode_Success
    except:
        routeRequestLogger.exception(request)
Ejemplo n.º 10
0
def getObjectAttributes():
    try:
        data = request.get_json()

        routeRequestLogger.info(request)

        if not checkParam(data, 'userId') or \
            not checkParam(data, 'objectId') or \
                not isValidUser(int(data['userId'])):
            return jsonify(**{'message': 'Bad params'}), ErrorCode_BadParams

        object_attrs = retrieveObjectAttributes(int(data['userId']),
                                                int(data['objectId']))
        attributes = []
        for obj in object_attrs:
            attributes.append(dict(obj))
        return jsonify(**{'attributes': attributes}), ErrorCode_Success
    except:
        routeRequestLogger.exception(request)
        return jsonify(
            **{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 11
0
def getRouteGroup():
    try:
        data = request.get_json()

        routeRequestLogger.info(request)

        if data is None:
            return jsonify(
                **{'message': 'No data found'}), ErrorCode_ServerError

        if not checkParam(data, 'userId') or not checkParam(data, 'filters'):
            return jsonify(**{'message': 'Bad params'}), ErrorCode_BadParams

        routes = getRoute(data['userId'], data['filters'])
        if not routes:
            return jsonify(**{'routeGroups': ''}), ErrorCode_NotFound

        route_groups = []
        try:
            for route in routes:
                route_groups.append(dict(route))
            return jsonify(**{'routeGroups': route_groups}), ErrorCode_Success
        except Exception as e:
            # ValueError and TypeError will be raised if routes is a RouteGroup object
            if e.__class__.__name__ in ('ValueError', 'TypeError'):
                return jsonify(**{
                    'routeGroups': dict(routes),
                    "id": routes.id
                }), ErrorCode_Success
            else:
                routeRequestLogger.exception(request)
                return jsonify(
                    **{'message': '{}'.format(str(e))}), ErrorCode_ServerError
    except:
        routeRequestLogger.exception(request)
        return jsonify(
            **{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 12
0
def viewAvailableRouteGroups():
    try:
        data = request.get_json()

        routeRequestLogger.info(request)

        if data is None:
            return jsonify(**{}), ErrorCode_ServerError

        if not checkParam(data, 'userId'):
            user = gimmeNewUser()
        else:
            user = retrieveUser(data['userId'])

        if not isValidUser(user.id):
            return jsonify(**{'message': 'Bad Params'}), ErrorCode_BadParams

        # routes = [{"id":route.id, "objectName" : route.objectName, "apiId": route.apiId} for route in getUserRoutes(user.id)]
        routes = []
        for route in getUserRoutes(user.id):
            attributes = retrieveObjectAttributes(data['userId'], route.id)
            new_list = {}
            for attr in attributes:
                new_list[attr.id] = dict(attr)
            routes.append({
                "id": route.id,
                "objectName": route.objectName,
                "apiId": route.apiId,
                "attributes": new_list
            })

        return jsonify(**{"groups": routes}), ErrorCode_Success
    except:
        routeRequestLogger.exception(request)
        return jsonify(
            **{"message": "Unexpected Error"}), ErrorCode_ServerError
Ejemplo n.º 13
0
def updateMultipleObjectAttributes():
    try:
        data = request.get_json()

        routeRequestLogger.info(request)

        if data is None:
            return jsonify(
                **{'message': 'No data found'}), ErrorCode_ServerError

        if not checkParam(data, 'userId') or not checkParam(
                data, 'objectId') or not checkParam(
                    data, 'attributes') or not checkParam(data, "deletedAttr"):
            return jsonify(**{'message': 'Bad params'}), ErrorCode_BadParams

        user = retrieveUser(data['userId'])
        attrToDelete = data['deletedAttr']
        for i in attrToDelete:
            deleteObjectAttributes(user.id, int(i))
        if user is None:
            return jsonify(
                **{'message': 'No data found'}), ErrorCode_ServerError
        if not isValidUser(user.id):
            return jsonify(**{'message': 'Bad Params'}), ErrorCode_BadParams

        allDBAttributes = retrieveObjectAttributes(user.id, data['objectId'])
        for dbAttributes in allDBAttributes:
            deleteObjectAttributes(user.id, dbAttributes.id)

        allAttributes = data['attributes']
        for attrId in allAttributes:
            modifiedAttrDict = allAttributes[attrId]
            if (modifiedAttrDict["name"] == ""
                    or modifiedAttrDict["type"] == ""):
                continue
            modifiedAttrDict['description'] = ""
            modifiedAttrDict['isUnique'] = True
            modifiedAttrDict['isEncrypted'] = True
            modifiedAttrDict['isNullable'] = True
            modifiedAttrDict['generationMethod'] = ""
            if isValidAttribute(modifiedAttrDict["name"], data['objectId'],
                                user.id):
                try:
                    if str(attrId) in attrToDelete:
                        deleteObjectAttributes(user.id, attrId)
                    else:
                        updateObjectAttributes(user.id, attrId,
                                               modifiedAttrDict)
                except Exception as e:
                    print(e)
            else:
                try:
                    newObjectAttributes = ObjectAttributes(
                        user.id, data['objectId'], modifiedAttrDict['name'],
                        modifiedAttrDict['type'],
                        modifiedAttrDict['description'],
                        modifiedAttrDict['isUnique'],
                        modifiedAttrDict['isEncrypted'],
                        modifiedAttrDict['isNullable'],
                        modifiedAttrDict['generationMethod'])
                    addObjectAttributes(user.id, data['objectId'],
                                        newObjectAttributes)
                except Exception as e:
                    print(e)

        # if updateObjectAttributes(user.id, data['attributeId'], **data['updatedObjectAttribute']):
        #     return jsonify(**{'attributeId': data['attributeId']}), ErrorCode_Success

        # return jsonify(**{'message': 'Update failed'}), ErrorCode_ServerError
        return jsonify(**{'message': 'Update success'}), ErrorCode_Success
    except:
        routeRequestLogger.exception(request)
        return jsonify(
            **{"message": "Unexpected Error"}), ErrorCode_ServerError