-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from EverythingMe/feature/datasources_v2
Refactor datasources (query runners)
- Loading branch information
Showing
25 changed files
with
1,102 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import json | ||
|
||
from redash import query_runner | ||
from redash.models import DataSource | ||
|
||
|
||
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 | ||
data_source.options = json.dumps(configuration) | ||
|
||
elif data_source.type == 'mysql': | ||
values = data_source.options.split(";") | ||
configuration = {} | ||
for value in values: | ||
k, v = value.split("=", 1) | ||
configuration[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() | ||
|
||
|
||
if __name__ == '__main__': | ||
for data_source in DataSource.all(): | ||
update(data_source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.