def post(self, data_source_id): data_source = models.DataSource.get_by_id(data_source_id) req = request.get_json(True) if not validate_configuration(req['type'], req['options']): abort(400) data_source.name = req['name'] data_source.options = json.dumps(req['options']) data_source.save() return data_source.to_dict(all=True)
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) if not validate_configuration(req['type'], req['options']): abort(400) datasource = models.DataSource.create(name=req['name'], type=req['type'], options=req['options']) return datasource.to_dict()
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) if not validate_configuration(req['type'], req['options']): abort(400) datasource = models.DataSource.create(org=self.current_org, name=req['name'], type=req['type'], options=json.dumps(req['options'])) return datasource.to_dict(all=True)
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) if not validate_configuration(req["type"], req["options"]): abort(400) datasource = models.DataSource.create(name=req["name"], type=req["type"], options=json.dumps(req["options"])) return datasource.to_dict(all=True)
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) if not validate_configuration(req['type'], req['options']): abort(400) datasource = models.DataSource.create_with_group(org=self.current_org, name=req['name'], type=req['type'], options=json.dumps(req['options'])) return datasource.to_dict(all=True)
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) data_source.replace_secret_placeholders(req['options']) if not validate_configuration(req['type'], req['options']): abort(400) data_source.name = req['name'] data_source.options = json.dumps(req['options']) data_source.save() return data_source.to_dict(all=True)
def validate_data_source_options(type, options): if not validate_configuration(type, options): print "Error: invalid configuration." exit()
def update(data_source): print "[%s] Old options: %s" % (data_source.name, data_source.options) if query_runner.validate_configuration(data_source.type, data_source.options): print "[%s] configuration already valid. skipping." % data_source.name return if data_source.type == 'pg': values = data_source.options.split(" ") configuration = {} for value in values: k, v = value.split("=", 1) configuration[k] = v if k == 'port': configuration[k] = int(v) data_source.options = json.dumps(configuration) elif data_source.type == 'mysql': mapping = { 'Server': 'host', 'User': '******', 'Pwd': 'passwd', 'Database': 'db' } values = data_source.options.split(";") configuration = {} for value in values: k, v = value.split("=", 1) configuration[mapping[k]] = v data_source.options = json.dumps(configuration) elif data_source.type == 'graphite': old_config = json.loads(data_source.options) configuration = {"url": old_config["url"]} if "verify" in old_config: configuration['verify'] = old_config['verify'] if "auth" in old_config: configuration['username'], configuration['password'] = old_config[ "auth"] data_source.options = json.dumps(configuration) elif data_source.type == 'url': data_source.options = json.dumps({"url": data_source.options}) elif data_source.type == 'script': data_source.options = json.dumps({"path": data_source.options}) elif data_source.type == 'mongo': data_source.type = 'mongodb' else: print "[%s] No need to convert type of: %s" % (data_source.name, data_source.type) print "[%s] New options: %s" % (data_source.name, data_source.options) data_source.save(only=data_source.dirty_fields)
def update(data_source): print "[%s] Old options: %s" % (data_source.name, data_source.options) if query_runner.validate_configuration(data_source.type, data_source.options): print "[%s] configuration already valid. skipping." % data_source.name return if data_source.type == 'pg': values = data_source.options.split(" ") configuration = {} for value in values: k, v = value.split("=", 1) configuration[k] = v if k == 'port': configuration[k] = int(v) data_source.options = json.dumps(configuration) elif data_source.type == 'mysql': mapping = { 'Server': 'host', 'User': '******', 'Pwd': 'passwd', 'Database': 'db' } values = data_source.options.split(";") configuration = {} for value in values: k, v = value.split("=", 1) configuration[mapping[k]] = v data_source.options = json.dumps(configuration) elif data_source.type == 'graphite': old_config = json.loads(data_source.options) configuration = { "url": old_config["url"] } if "verify" in old_config: configuration['verify'] = old_config['verify'] if "auth" in old_config: configuration['username'], configuration['password'] = old_config["auth"] data_source.options = json.dumps(configuration) elif data_source.type == 'url': data_source.options = json.dumps({"url": data_source.options}) elif data_source.type == 'script': data_source.options = json.dumps({"path": data_source.options}) elif data_source.type == 'mongo': data_source.type = 'mongodb' else: print "[%s] No need to convert type of: %s" % (data_source.name, data_source.type) print "[%s] New options: %s" % (data_source.name, data_source.options) data_source.save()