Beispiel #1
0
    def post(self, data_source_id):
        data_source = models.DataSource.get_by_id_and_org(
            data_source_id, self.current_org)
        req = request.get_json(True)

        schema = get_configuration_schema_for_query_runner_type(req['type'])
        if schema is None:
            abort(400)
        try:
            data_source.options.set_schema(schema)
            data_source.options.update(filter_none(req['options']))
        except ValidationError:
            abort(400)

        data_source.type = req['type']
        data_source.name = req['name']
        models.db.session.add(data_source)

        try:
            models.db.session.commit()
        except IntegrityError as e:
            if req['name'] in e.message:
                abort(400,
                      message="Data source with the name {} already exists.".
                      format(req['name']))

            abort(400)

        self.record_event({
            'action': 'edit',
            'object_id': data_source.id,
            'object_type': 'datasource',
        })

        return data_source.to_dict(all=True)
Beispiel #2
0
    def post(self, data_source_id):
        data_source = models.DataSource.get_by_id_and_org(data_source_id, self.current_org)
        req = request.get_json(True)

        schema = get_configuration_schema_for_query_runner_type(req['type'])
        if schema is None:
            abort(400)
        try:
            data_source.options.set_schema(schema)
            data_source.options.update(filter_none(req['options']))
        except ValidationError:
            abort(400)

        data_source.type = req['type']
        data_source.name = req['name']
        models.db.session.add(data_source)

        try:
            models.db.session.commit()
        except IntegrityError as e:
            if req['name'] in e.message:
                abort(400, message="Data source with the name {} already exists.".format(req['name']))

            abort(400)

        return data_source.to_dict(all=True)
Beispiel #3
0
    def test_skips_nones(self):
        d = {
            'a': 1,
            'b': None
        }

        self.assertDictEqual(filter_none(d), {'a': 1})
Beispiel #4
0
    def post(self, data_source_id):
        data_source = models.DataSource.get_by_id_and_org(
            data_source_id, self.current_org)
        req = request.get_json(True)

        schema = get_configuration_schema_for_query_runner_type(req['type'])
        if schema is None:
            abort(400)
        try:
            data_source.options.set_schema(schema)
            data_source.options.update(filter_none(req['options']))
        except ValidationError:
            abort(400)

        data_source.type = req['type']
        data_source.name = req['name']
        models.db.session.add(data_source)

        # Refresh the stored schemas when a data source is updated
        refresh_schemas.apply_async(queue=settings.SCHEMAS_REFRESH_QUEUE)

        try:
            models.db.session.commit()
        except IntegrityError as e:
            if req['name'] in e.message:
                abort(400,
                      message="Data source with the name {} already exists.".
                      format(req['name']))

            abort(400)

        return data_source.to_dict(all=True)
Beispiel #5
0
    def post(self):
        req = request.get_json(True)
        require_fields(req, ('options', 'name', 'type'))

        schema = get_configuration_schema_for_query_runner_type(req['type'])
        if schema is None:
            abort(400)

        config = ConfigurationContainer(filter_none(req['options']), schema)
        # from IPython import embed
        # embed()
        if not config.is_valid():
            abort(400)

        try:
            datasource = models.DataSource.create_with_group(org=self.current_org,
                                                             name=req['name'],
                                                             type=req['type'],
                                                             options=config)

            models.db.session.commit()
        except IntegrityError as e:
            if req['name'] in e.message:
                abort(400, message="Data source with the name {} already exists.".format(req['name']))

            abort(400)

        self.record_event({
            'action': 'create',
            'object_id': datasource.id,
            'object_type': 'datasource'
        })

        return datasource.to_dict(all=True)
Beispiel #6
0
    def test_skips_nones(self):
        d = {
            'a': 1,
            'b': None
        }

        self.assertDictEqual(filter_none(d), {'a': 1})
Beispiel #7
0
    def post(self):
        req = request.get_json(True)
        required_fields = ('options', 'name', 'type')
        for f in required_fields:
            if f not in req:
                abort(400)

        schema = get_configuration_schema_for_query_runner_type(req['type'])
        if schema is None:
            abort(400)

        config = ConfigurationContainer(filter_none(req['options']), schema)
        # from IPython import embed
        # embed()
        if not config.is_valid():
            abort(400)

        datasource = models.DataSource.create_with_group(org=self.current_org,
                                                         name=req['name'],
                                                         type=req['type'],
                                                         options=config)

        models.db.session.commit()

        self.record_event({
            'action': 'create',
            'object_id': datasource.id,
            'object_type': 'datasource'
        })

        return datasource.to_dict(all=True)
Beispiel #8
0
    def post(self):
        req = request.get_json(True)
        require_fields(req, ("options", "name", "type"))

        schema = get_configuration_schema_for_query_runner_type(req["type"])
        if schema is None:
            abort(400)

        config = ConfigurationContainer(filter_none(req["options"]), schema)
        if not config.is_valid():
            abort(400)

        try:
            datasource = models.DataSource.create_with_group(
                org=self.current_org,
                name=req["name"],
                type=req["type"],
                description=req["description"] if "description" in req else "",
                options=config,
            )

            models.db.session.commit()

            # Refresh the stored schemas when a new data source is added to the list
            refresh_schema.delay(datasource.id)

        except IntegrityError as e:
            models.db.session.rollback()
            if req["name"] in str(e):
                abort(
                    400,
                    message="Data source with the name {} already exists.".
                    format(req["name"]),
                )

            abort(400)

        self.record_event({
            "action": "create",
            "object_id": datasource.id,
            "object_type": "datasource",
        })

        return datasource.to_dict(all=True)
Beispiel #9
0
    def post(self, data_source_id):
        data_source = models.DataSource.get_by_id_and_org(
            data_source_id, self.current_org)
        req = request.get_json(True)

        schema = get_configuration_schema_for_query_runner_type(req["type"])
        if schema is None:
            abort(400)
        try:
            data_source.options.set_schema(schema)
            data_source.options.update(filter_none(req["options"]))
        except ValidationError:
            abort(400)

        data_source.type = req["type"]
        data_source.name = req["name"]
        data_source.description = req[
            "description"] if "description" in req else ""
        models.db.session.add(data_source)

        # Refresh the stored schemas when a data source is updated
        refresh_schema.delay(data_source.id)

        try:
            models.db.session.commit()
        except IntegrityError as e:
            models.db.session.rollback()
            if req["name"] in str(e):
                abort(
                    400,
                    message="Data source with the name {} already exists.".
                    format(req["name"]),
                )

            abort(400)

        self.record_event({
            "action": "edit",
            "object_id": data_source.id,
            "object_type": "datasource"
        })

        return data_source.to_dict(all=True)
Beispiel #10
0
    def post(self):
        req = request.get_json(True)
        required_fields = ('options', 'name', 'type')
        for f in required_fields:
            if f not in req:
                abort(400)

        schema = get_configuration_schema_for_query_runner_type(req['type'])
        if schema is None:
            abort(400)

        config = ConfigurationContainer(filter_none(req['options']), schema)
        # from IPython import embed
        # embed()
        if not config.is_valid():
            abort(400)

        try:
            datasource = models.DataSource.create_with_group(
                org=self.current_org,
                name=req['name'],
                type=req['type'],
                options=config)

            models.db.session.commit()

            # Refresh the stored schemas when a new data source is added to the list
            refresh_schemas.apply_async(queue=settings.SCHEMAS_REFRESH_QUEUE)
        except IntegrityError as e:
            if req['name'] in e.message:
                abort(400,
                      message="Data source with the name {} already exists.".
                      format(req['name']))

            abort(400)

        self.record_event({
            'action': 'create',
            'object_id': datasource.id,
            'object_type': 'datasource'
        })

        return datasource.to_dict(all=True)
Beispiel #11
0
    def post(self, data_source_id):
        data_source = models.DataSource.get_by_id_and_org(data_source_id, self.current_org)
        req = request.get_json(True)

        schema = get_configuration_schema_for_query_runner_type(req['type'])
        if schema is None:
            abort(400)
        try:
            data_source.options.set_schema(schema)
            data_source.options.update(filter_none(req['options']))
        except ValidationError:
            abort(400)

        data_source.type = req['type']
        data_source.name = req['name']
        models.db.session.add(data_source)
        models.db.session.commit()

        return data_source.to_dict(all=True)
Beispiel #12
0
    def post(self, data_source_id):
        data_source = models.DataSource.get_by_id_and_org(
            data_source_id, self.current_org)
        req = request.get_json(True)

        schema = get_configuration_schema_for_query_runner_type(req["type"])
        if schema is None:
            abort(400)
        try:
            data_source.options.set_schema(schema)
            data_source.options.update(filter_none(req["options"]))
        except ValidationError:
            abort(400)

        data_source.type = req["type"]
        data_source.name = req["name"]
        models.db.session.add(data_source)

        try:
            models.db.session.commit()
        except IntegrityError as e:
            if req["name"] in str(e):
                abort(
                    400,
                    message="同名数据源 {} 已经存在。".format(req["name"]),
                )

            abort(400)

        self.record_event({
            "action": "edit",
            "object_id": data_source.id,
            "object_type": "datasource"
        })

        return data_source.to_dict(all=True)
Beispiel #13
0
    def post(self):
        req = request.get_json(True)
        require_fields(req, ("options", "name", "type"))

        schema = get_configuration_schema_for_query_runner_type(req["type"])
        if schema is None:
            abort(400)

        config = ConfigurationContainer(filter_none(req["options"]), schema)
        if not config.is_valid():
            abort(400)

        try:
            datasource = models.DataSource.create_with_group(
                org=self.current_org,
                name=req["name"],
                type=req["type"],
                options=config)

            models.db.session.commit()
        except IntegrityError as e:
            if req["name"] in str(e):
                abort(
                    400,
                    message="同名数据源 {} 已经存在。".format(req["name"]),
                )

            abort(400)

        self.record_event({
            "action": "create",
            "object_id": datasource.id,
            "object_type": "datasource",
        })

        return datasource.to_dict(all=True)
Beispiel #14
0
    def test_skips_nones(self):
        d = {"a": 1, "b": None}

        self.assertDictEqual(filter_none(d), {"a": 1})