Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension points for data source links and config properties customization. #2892

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/app/pages/queries/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ <h3>
{{ds.name}}
</ui-select-choices>
</ui-select>
<datasource-link datasource-id="query.data_source_id"></datasource-link>
</div>

<div class="editor__left__schema" ng-if="sourceMode">
Expand Down
36 changes: 22 additions & 14 deletions redash/query_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class NotSupported(Exception):

class BaseQueryRunner(object):
noop_query = None
configuration_properties = None

def __init__(self, configuration):
self.syntax = 'sql'
Expand All @@ -76,6 +77,12 @@ def annotate_query(cls):
def configuration_schema(cls):
return {}

@classmethod
def add_configuration_property(cls, property, value):
if cls.configuration_properties is None:
raise NotImplementedError()
cls.configuration_properties[property] = value

def test_connection(self):
if self.noop_query is None:
raise NotImplementedError()
Expand Down Expand Up @@ -149,25 +156,26 @@ class BaseHTTPQueryRunner(BaseQueryRunner):
url_title = 'URL base path'
username_title = 'HTTP Basic Auth Username'
password_title = 'HTTP Basic Auth Password'
configuration_properties = {
'url': {
'type': 'string',
'title': url_title,
},
'username': {
'type': 'string',
'title': username_title,
},
'password': {
'type': 'string',
'title': password_title,
},
}

@classmethod
def configuration_schema(cls):
schema = {
'type': 'object',
'properties': {
'url': {
'type': 'string',
'title': cls.url_title,
},
'username': {
'type': 'string',
'title': cls.username_title,
},
'password': {
'type': 'string',
'title': cls.password_title,
},
},
'properties': cls.configuration_properties,
'required': ['url'],
'secret': ['password']
}
Expand Down
69 changes: 35 additions & 34 deletions redash/query_runner/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,40 @@ def _get_query_results(jobs, project_id, location, job_id, start_index):

class BigQuery(BaseQueryRunner):
noop_query = "SELECT 1"
configuration_properties = {
'projectId': {
'type': 'string',
'title': 'Project ID'
},
'jsonKeyFile': {
"type": "string",
'title': 'JSON Key File'
},
'totalMBytesProcessedLimit': {
"type": "number",
'title': 'Scanned Data Limit (MB)'
},
'userDefinedFunctionResourceUri': {
"type": "string",
'title': 'UDF Source URIs (i.e. gs://bucket/date_utils.js, gs://bucket/string_utils.js )'
},
'useStandardSql': {
"type": "boolean",
'title': "Use Standard SQL (Beta)",
},
'location': {
"type": "string",
"title": "Processing Location",
},
'loadSchema': {
"type": "boolean",
"title": "Load Schema"
},
'maximumBillingTier': {
"type": "number",
"title": "Maximum Billing Tier"
}
}

@classmethod
def enabled(cls):
Expand All @@ -91,40 +125,7 @@ def enabled(cls):
def configuration_schema(cls):
return {
'type': 'object',
'properties': {
'projectId': {
'type': 'string',
'title': 'Project ID'
},
'jsonKeyFile': {
"type": "string",
'title': 'JSON Key File'
},
'totalMBytesProcessedLimit': {
"type": "number",
'title': 'Scanned Data Limit (MB)'
},
'userDefinedFunctionResourceUri': {
"type": "string",
'title': 'UDF Source URIs (i.e. gs://bucket/date_utils.js, gs://bucket/string_utils.js )'
},
'useStandardSql': {
"type": "boolean",
'title': "Use Standard SQL (Beta)",
},
'location': {
"type": "string",
"title": "Processing Location",
},
'loadSchema': {
"type": "boolean",
"title": "Load Schema"
},
'maximumBillingTier': {
"type": "number",
"title": "Maximum Billing Tier"
}
},
'properties': cls.configuration_properties,
'required': ['jsonKeyFile', 'projectId'],
"order": ['projectId', 'jsonKeyFile', 'loadSchema', 'useStandardSql', 'location', 'totalMBytesProcessedLimit', 'maximumBillingTier', 'userDefinedFunctionResourceUri'],
'secret': ['jsonKeyFile']
Expand Down
63 changes: 32 additions & 31 deletions redash/query_runner/cass.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ def default(self, o):

class Cassandra(BaseQueryRunner):
noop_query = "SELECT dateof(now()) FROM system.local"
configuration_properties = {
'host': {
'type': 'string',
},
'port': {
'type': 'number',
'default': 9042,
},
'keyspace': {
'type': 'string',
'title': 'Keyspace name'
},
'username': {
'type': 'string',
'title': 'Username'
},
'password': {
'type': 'string',
'title': 'Password'
},
'protocol': {
'type': 'number',
'title': 'Protocol Version',
'default': 3
},
'timeout': {
'type': 'number',
'title': 'Timeout',
'default': 10
}
}

@classmethod
def enabled(cls):
Expand All @@ -32,37 +63,7 @@ def enabled(cls):
def configuration_schema(cls):
return {
'type': 'object',
'properties': {
'host': {
'type': 'string',
},
'port': {
'type': 'number',
'default': 9042,
},
'keyspace': {
'type': 'string',
'title': 'Keyspace name'
},
'username': {
'type': 'string',
'title': 'Username'
},
'password': {
'type': 'string',
'title': 'Password'
},
'protocol': {
'type': 'number',
'title': 'Protocol Version',
'default': 3
},
'timeout': {
'type': 'number',
'title': 'Timeout',
'default': 10
}
},
'properties': cls.configuration_properties,
'required': ['keyspace', 'host']
}

Expand Down
25 changes: 13 additions & 12 deletions redash/query_runner/dynamodb_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@


class DynamoDBSQL(BaseSQLQueryRunner):
configuration_properties = {
"region": {
"type": "string",
"default": "us-east-1"
},
"access_key": {
"type": "string",
},
"secret_key": {
"type": "string",
}
}
@classmethod
def configuration_schema(cls):
return {
"type": "object",
"properties": {
"region": {
"type": "string",
"default": "us-east-1"
},
"access_key": {
"type": "string",
},
"secret_key": {
"type": "string",
}
},
"properties": cls.configuration_properties,
"required": ["access_key", "secret_key"],
"secret": ["secret_key"]
}
Expand Down
29 changes: 15 additions & 14 deletions redash/query_runner/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,26 @@

class BaseElasticSearch(BaseQueryRunner):
DEBUG_ENABLED = False
configuration_properties = {
'server': {
'type': 'string',
'title': 'Base URL'
},
'basic_auth_user': {
'type': 'string',
'title': 'Basic Auth User'
},
'basic_auth_password': {
'type': 'string',
'title': 'Basic Auth Password'
}
}

@classmethod
def configuration_schema(cls):
return {
'type': 'object',
'properties': {
'server': {
'type': 'string',
'title': 'Base URL'
},
'basic_auth_user': {
'type': 'string',
'title': 'Basic Auth User'
},
'basic_auth_password': {
'type': 'string',
'title': 'Basic Auth Password'
}
},
'properties': cls.configuration_properties,
"secret": ["basic_auth_password"],
"required": ["server"]
}
Expand Down
13 changes: 7 additions & 6 deletions redash/query_runner/google_spreadsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ def request(self, *args, **kwargs):


class GoogleSpreadsheet(BaseQueryRunner):
configuration_properties = {
'jsonKeyFile': {
"type": "string",
'title': 'JSON Key File'
}
}

@classmethod
def annotate_query(cls):
Expand All @@ -164,12 +170,7 @@ def enabled(cls):
def configuration_schema(cls):
return {
'type': 'object',
'properties': {
'jsonKeyFile': {
"type": "string",
'title': 'JSON Key File'
}
},
'properties': cls.configuration_properties,
'required': ['jsonKeyFile'],
'secret': ['jsonKeyFile']
}
Expand Down
Loading