Skip to content

Commit

Permalink
Merge pull request getredash#882 from tsibley/new-data-source-via-cli
Browse files Browse the repository at this point in the history
CLI: Restore ability to pass JSON options string for a new data source
  • Loading branch information
arikfr committed Mar 6, 2016
2 parents 8f937b7 + d07bf7e commit bac4025
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions redash/cli/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def new(name=None, type=None, options=None):
else:
validate_data_source_type(type)

if options is None:
query_runner = query_runners[type]
schema = query_runner.configuration_schema()
query_runner = query_runners[type]
schema = query_runner.configuration_schema()

if options is None:
types = {
'string': unicode,
'number': int,
Expand All @@ -72,11 +72,14 @@ def new(name=None, type=None, options=None):
options_obj[k] = value

options = ConfigurationContainer(options_obj, schema)
if not options.is_valid():
print "Error: invalid configuration."
exit()
else:
options = ConfigurationContainer(json.loads(options), schema)

if not options.is_valid():
print "Error: invalid configuration."
exit()

print "Creating {} data source ({}) with options:\n{}".format(type, name, options)
print "Creating {} data source ({}) with options:\n{}".format(type, name, options.to_json())

data_source = models.DataSource.create(name=name,
type=type,
Expand Down

0 comments on commit bac4025

Please sign in to comment.