From 41c41beb5158d9b742f4853b674040fa8ebebe7c Mon Sep 17 00:00:00 2001 From: Marina Samuel Date: Fri, 7 Sep 2018 16:13:10 -0400 Subject: [PATCH] Closes #553: Port data source version code to an extension. --- client/app/pages/data-sources/show.js | 19 --------------- .../pages/queries/get-data-source-version.js | 19 --------------- client/app/pages/queries/query.html | 2 +- client/app/pages/queries/view.js | 1 - client/app/services/data-source.js | 3 --- redash/cli/data_sources.py | 24 ------------------- redash/handlers/api.py | 3 +-- redash/handlers/data_sources.py | 18 -------------- redash/query_runner/__init__.py | 23 ------------------ redash/query_runner/mysql.py | 2 -- redash/query_runner/pg.py | 4 ---- requirements.txt | 2 +- 12 files changed, 3 insertions(+), 117 deletions(-) delete mode 100644 client/app/pages/queries/get-data-source-version.js diff --git a/client/app/pages/data-sources/show.js b/client/app/pages/data-sources/show.js index 584aa76e96..ab2c461ba0 100644 --- a/client/app/pages/data-sources/show.js +++ b/client/app/pages/data-sources/show.js @@ -75,30 +75,11 @@ function DataSourceCtrl( }); } - function getDataSourceVersion(callback) { - DataSource.version({ id: $scope.dataSource.id }, (httpResponse) => { - if (httpResponse.ok) { - const versionNumber = httpResponse.message; - toastr.success(`Success. Version: ${versionNumber}`); - } else { - toastr.error(httpResponse.message, 'Version Test Failed:', { timeOut: 10000 }); - } - callback(); - }, (httpResponse) => { - logger('Failed to get data source version: ', httpResponse.status, httpResponse.statusText, httpResponse); - toastr.error('Unknown error occurred while performing data source version test. Please try again later.', 'Data Source Version Test Failed:', { timeOut: 10000 }); - callback(); - }); - } - $scope.actions = [ { name: 'Delete', class: 'btn-danger', callback: deleteDataSource }, { name: 'Test Connection', class: 'btn-default pull-right', callback: testConnection, disableWhenDirty: true, }, - { - name: 'Test Data Source Version', class: 'btn-default', callback: getDataSourceVersion, disableWhenDirty: true, - }, ]; } diff --git a/client/app/pages/queries/get-data-source-version.js b/client/app/pages/queries/get-data-source-version.js deleted file mode 100644 index 90df5cb61c..0000000000 --- a/client/app/pages/queries/get-data-source-version.js +++ /dev/null @@ -1,19 +0,0 @@ -function GetDataSourceVersionCtrl(Events, toastr, $scope, DataSource, $route) { - 'ngInject'; - - this.getDataSourceVersion = DataSource.version({ - id: $route.current.locals.query.data_source_id, - }); -} - -const GetDataSourceVersionInfo = { - bindings: { - onRefresh: '&', - }, - controller: GetDataSourceVersionCtrl, - template: '{{ $ctrl.getDataSourceVersion.message }}', -}; - -export default function (ngModule) { - ngModule.component('getDataSourceVersion', GetDataSourceVersionInfo); -} diff --git a/client/app/pages/queries/query.html b/client/app/pages/queries/query.html index 1fffd3bb2c..0344a3f10d 100644 --- a/client/app/pages/queries/query.html +++ b/client/app/pages/queries/query.html @@ -85,7 +85,7 @@

- +
diff --git a/client/app/pages/queries/view.js b/client/app/pages/queries/view.js index 6d864c8c02..c78277bfd0 100644 --- a/client/app/pages/queries/view.js +++ b/client/app/pages/queries/view.js @@ -320,7 +320,6 @@ function QueryViewCtrl( } $scope.dataSource = find($scope.dataSources, ds => ds.id === $scope.query.data_source_id); - document.getElementById('data-source-version').innerHTML = ''; getSchema(); }; diff --git a/client/app/services/data-source.js b/client/app/services/data-source.js index d26c37b947..39d8a78ade 100644 --- a/client/app/services/data-source.js +++ b/client/app/services/data-source.js @@ -21,9 +21,6 @@ function DataSource($q, $resource, $http) { isArray: false, url: 'api/data_sources/:id/test', }, - version: { - method: 'GET', cache: false, isArray: false, url: 'api/data_sources/:id/version', - }, }; const DataSourceResource = $resource('api/data_sources/:id', { id: '@id' }, actions); diff --git a/redash/cli/data_sources.py b/redash/cli/data_sources.py index 0b7b18ff5d..79827132a0 100644 --- a/redash/cli/data_sources.py +++ b/redash/cli/data_sources.py @@ -67,30 +67,6 @@ def test(name, organization='default'): print("Couldn't find data source named: {}".format(name)) exit(1) -@manager.command() -@click.argument('name') -@click.option('--org', 'organization', default='default', - help="The organization the user belongs to " - "(leave blank for 'default').") -def get_data_source_version(name, organization='default'): - """Get version of data source connection by issuing a trivial query.""" - try: - org = models.Organization.get_by_slug(organization) - data_source = models.DataSource.query.filter( - models.DataSource.name == name, - models.DataSource.org == org).one() - print("Testing get connection data source version: {} (id={})".format( - name, data_source.id)) - try: - info = data_source.query_runner.get_data_source_version() - except Exception as e: - print("Failure: {}".format(e)) - exit(1) - else: - print(info) - except NoResultFound: - print("Couldn't find data source named: {}".format(name)) - exit(1) @manager.command() @click.argument('name', default=None, required=False) diff --git a/redash/handlers/api.py b/redash/handlers/api.py index 5e7eb483f9..4518bffcce 100644 --- a/redash/handlers/api.py +++ b/redash/handlers/api.py @@ -7,7 +7,7 @@ from redash.handlers.permissions import ObjectPermissionsListResource, CheckPermissionResource from redash.handlers.alerts import AlertResource, AlertListResource, AlertSubscriptionListResource, AlertSubscriptionResource from redash.handlers.dashboards import DashboardListResource, DashboardResource, DashboardShareResource, PublicDashboardResource -from redash.handlers.data_sources import DataSourceTypeListResource, DataSourceListResource, DataSourceSchemaResource, DataSourceResource, DataSourcePauseResource, DataSourceTestResource, DataSourceVersionResource +from redash.handlers.data_sources import DataSourceTypeListResource, DataSourceListResource, DataSourceSchemaResource, DataSourceResource, DataSourcePauseResource, DataSourceTestResource from redash.handlers.events import EventsResource from redash.handlers.queries import QueryForkResource, QueryRefreshResource, QueryListResource, QueryRecentResource, QuerySearchResource, QueryResource, MyQueriesResource, QueryVersionListResource, ChangeResource from redash.handlers.query_results import QueryResultListResource, QueryResultResource, JobResource, QueryResultSetResource @@ -58,7 +58,6 @@ def json_representation(data, code, headers=None): api.add_org_resource(DataSourceSchemaResource, '/api/data_sources//schema') api.add_org_resource(DataSourcePauseResource, '/api/data_sources//pause') api.add_org_resource(DataSourceTestResource, '/api/data_sources//test') -api.add_org_resource(DataSourceVersionResource, '/api/data_sources//version') api.add_org_resource(DataSourceResource, '/api/data_sources/', endpoint='data_source') api.add_org_resource(GroupListResource, '/api/groups', endpoint='groups') diff --git a/redash/handlers/data_sources.py b/redash/handlers/data_sources.py index 60de6e04d7..72fd83dce2 100644 --- a/redash/handlers/data_sources.py +++ b/redash/handlers/data_sources.py @@ -216,21 +216,3 @@ def post(self, data_source_id): return {"message": unicode(e), "ok": False} else: return {"message": "success", "ok": True} - -class DataSourceVersionResource(BaseResource): - def get(self, data_source_id): - data_source = get_object_or_404(models.DataSource.get_by_id_and_org, data_source_id, self.current_org) - require_access(data_source.groups, self.current_user, view_only) - self.record_event({ - 'action': 'test', - 'object_id': data_source_id, - 'object_type': 'data_source_version', - }) - try: - version_info = data_source.query_runner.get_data_source_version() - except Exception as e: - return {"message": unicode(e), "ok": False} - else: - return {"message": version_info, "ok": True} - - diff --git a/redash/query_runner/__init__.py b/redash/query_runner/__init__.py index cbff54f92c..81900351d8 100644 --- a/redash/query_runner/__init__.py +++ b/redash/query_runner/__init__.py @@ -53,7 +53,6 @@ class NotSupported(Exception): class BaseQueryRunner(object): noop_query = None - data_source_version_query = None configuration_properties = None def __init__(self, configuration): @@ -86,28 +85,6 @@ def add_configuration_property(cls, property, value): raise NotImplementedError() cls.configuration_properties[property] = value - def get_data_source_version(self): - if self.data_source_version_query is None: - raise NotImplementedError - data, error = self.run_query(self.data_source_version_query, None) - - if error is not None: - raise Exception(error) - - try: - version = json.loads(data)['rows'][0]['version'] - except KeyError as e: - raise Exception(e) - - if self.data_source_version_post_process == "split by space take second": - version = version.split(" ")[1] - elif self.data_source_version_post_process == "split by space take last": - version = version.split(" ")[-1] - elif self.data_source_version_post_process == "none": - version = version - - return version - def test_connection(self): if self.noop_query is None: raise NotImplementedError() diff --git a/redash/query_runner/mysql.py b/redash/query_runner/mysql.py index 82f7133620..35babdc3b8 100644 --- a/redash/query_runner/mysql.py +++ b/redash/query_runner/mysql.py @@ -56,8 +56,6 @@ class Mysql(BaseSQLQueryRunner): "info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight." } } - data_source_version_query = "select version()" - data_source_version_post_process = "none" @classmethod def configuration_schema(cls): diff --git a/redash/query_runner/pg.py b/redash/query_runner/pg.py index dd239889e1..8590846e69 100644 --- a/redash/query_runner/pg.py +++ b/redash/query_runner/pg.py @@ -47,8 +47,6 @@ def _wait(conn, timeout=None): class PostgreSQL(BaseSQLQueryRunner): noop_query = "SELECT 1" - data_source_version_query = "select version()" - data_source_version_post_process = "split by space take second" configuration_properties = { "user": { "type": "string" @@ -222,8 +220,6 @@ class Redshift(PostgreSQL): "default": "prefer" } } - data_source_version_query = "select version()" - data_source_version_post_process = "split by space take last" @classmethod def type(cls): diff --git a/requirements.txt b/requirements.txt index 2eba2a2dd3..00202daf09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -54,4 +54,4 @@ disposable-email-domains # Uncomment the requirement for ldap3 if using ldap. # It is not included by default because of the GPL license conflict. # ldap3==2.2.4 -redash-stmo>=2018.9.0 +redash-stmo>=2018.9.1