コード例 #1
0
@device.route('/device/<device_id>/template/<template_id>', methods=['DELETE'])
def flask_remove_template_from_device(device_id, template_id):
    try:
        result = DeviceHandler.remove_template_from_device(
            request, device_id, template_id)
        resp = make_response(json.dumps(result), 200)
        resp.mimetype = "application/json"
        return resp
    except HTTPRequestError as e:
        if isinstance(e.message, dict):
            return make_response(json.dumps(e.message), e.error_code)
        else:
            return format_response(e.error_code, e.message)


@device.route('/device/template/<template_id>', methods=['GET'])
def flask_get_by_template(template_id):
    try:
        result = DeviceHandler.get_by_template(request, template_id)
        resp = make_response(json.dumps(result), 200)
        resp.mimetype = "application/json"
        return resp
    except HTTPRequestError as e:
        if isinstance(e.message, dict):
            return make_response(json.dumps(e.message), e.error_code)
        else:
            return format_response(e.error_code, e.message)


app.register_blueprint(device)
コード例 #2
0
ファイル: LoggerHandler.py プロジェクト: dojot/device-manager
        result = {'level': LOG.get_log_level()}

        return result


@logger.route('/log', methods=['PUT'])
def flask_update_log_level():
    try:
        content_type = request.headers.get('Content-Type')
        data_request = request.data

        _, json_payload = parse_payload(content_type, data_request, log_schema)
        LoggerHandler.update_log_level(json_payload['level'])

        return make_response('', 200)

    except HTTPRequestError as error:
        if isinstance(error.message, dict):
            return make_response(jsonify(error.message), error.error_code)
        return format_response(error.error_code, error.message)


@logger.route('/log', methods=['GET'])
def flask_get_log_level():
    result = LoggerHandler.get_log_level()

    return make_response(jsonify(result), 200)


app.register_blueprint(logger)
コード例 #3
0
            return make_response(jsonify(e.message), e.error_code)
        return format_response(e.error_code, e.message)


@template.route('/template/<template_id>', methods=['PUT'])
def flask_update_template(template_id):
    try:
        # retrieve the authorization token
        token = retrieve_auth_token(request)

        params = {
            'content_type': request.headers.get('Content-Type'),
            'data': request.data
        }

        result = TemplateHandler.update_template(params, template_id, token)
        LOGGER.info(f"Updating template with id: {template_id}")
        return make_response(jsonify(result), 200)
    except ValidationError as errors:
        results = {'message': 'failed to parse attr', 'errors': errors.messages}
        LOGGER.error(f' Error in load attrs {errors.messages}')
        return make_response(jsonify(results), 400)
    except HTTPRequestError as error:
        LOGGER.error(f" {error.message}")
        if isinstance(error.message, dict):
            return make_response(jsonify(error.message), error.error_code)
        return format_response(error.error_code, error.message)


app.register_blueprint(template)
コード例 #4
0
ファイル: ImportHandler.py プロジェクト: dojot/device-manager
@importing.route('/import', methods=['POST'])
def flask_import_data():
    try:
        LOGGER.info(f" Starting importing data...")

        # retrieve the authorization token
        token = retrieve_auth_token(request)

        # retrieve header and body of request
        content_type = request.headers.get('Content-Type')
        data = request.data

        result = ImportHandler.import_data(data, token, content_type)

        LOGGER.info(f" Imported data!")

        return make_response(jsonify(result), 201)

    except ValidationError as e:
        results = {'message': 'failed to parse attr', 'errors': e}
        LOGGER.error(f" {e}")
        return make_response(jsonify(results), 400)
    except HTTPRequestError as error:
        LOGGER.error(f" {error.message}")
        if isinstance(error.message, dict):
            return make_response(jsonify(error.message), error.error_code)
        return format_response(error.error_code, error.message)


app.register_blueprint(importing)