-
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 #498 from EverythingMe/feature/ds_admin
Feature: datasources web admin (closes #193)
- Loading branch information
Showing
27 changed files
with
410 additions
and
127 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
from playhouse.migrate import PostgresqlMigrator, migrate | ||
|
||
from redash.models import db | ||
|
||
if __name__ == '__main__': | ||
db.connect_db() | ||
migrator = PostgresqlMigrator(db.database) | ||
|
||
with db.database.transaction(): | ||
migrate( | ||
migrator.drop_not_null('queries', 'data_source_id'), | ||
) | ||
|
||
db.close_db(None) | ||
|
||
|
||
|
||
|
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,44 @@ | ||
from base64 import b64encode | ||
import json | ||
from redash.models import DataSource | ||
|
||
|
||
def convert_p12_to_pem(p12file): | ||
from OpenSSL import crypto | ||
with open(p12file, 'rb') as f: | ||
p12 = crypto.load_pkcs12(f.read(), "notasecret") | ||
|
||
return crypto.dump_privatekey(crypto.FILETYPE_PEM, p12.get_privatekey()) | ||
|
||
if __name__ == '__main__': | ||
|
||
for ds in DataSource.all(): | ||
|
||
if ds.type == 'bigquery': | ||
options = json.loads(ds.options) | ||
|
||
if 'jsonKeyFile' in options: | ||
continue | ||
|
||
new_options = { | ||
'projectId': options['projectId'], | ||
'jsonKeyFile': b64encode(json.dumps({ | ||
'client_email': options['serviceAccount'], | ||
'private_key': convert_p12_to_pem(options['privateKey']) | ||
})) | ||
} | ||
|
||
ds.options = json.dumps(new_options) | ||
ds.save() | ||
elif ds.type == 'google_spreadsheets': | ||
options = json.loads(ds.options) | ||
if 'jsonKeyFile' in options: | ||
continue | ||
|
||
with open(options['credentialsFilePath']) as f: | ||
new_options = { | ||
'jsonKeyFile': b64encode(f.read()) | ||
} | ||
|
||
ds.options = json.dumps(new_options) | ||
ds.save() |
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
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,47 @@ | ||
(function () { | ||
var DataSourcesCtrl = function ($scope, $location, growl, Events, DataSource) { | ||
Events.record(currentUser, "view", "page", "admin/data_sources"); | ||
$scope.$parent.pageTitle = "Data Sources"; | ||
|
||
$scope.dataSources = DataSource.query(); | ||
|
||
$scope.openDataSource = function(datasource) { | ||
$location.path('/data_sources/' + datasource.id); | ||
}; | ||
|
||
$scope.deleteDataSource = function(event, datasource) { | ||
event.stopPropagation(); | ||
Events.record(currentUser, "delete", "datasource", datasource.id); | ||
datasource.$delete(function(resource) { | ||
growl.addSuccessMessage("Data source deleted succesfully."); | ||
this.$parent.dataSources = _.without(this.dataSources, resource); | ||
}.bind(this), function(httpResponse) { | ||
console.log("Failed to delete data source: ", httpResponse.status, httpResponse.statusText, httpResponse.data); | ||
growl.addErrorMessage("Failed to delete data source."); | ||
}); | ||
} | ||
}; | ||
|
||
var DataSourceCtrl = function ($scope, $routeParams, $http, $location, Events, DataSource) { | ||
Events.record(currentUser, "view", "page", "admin/data_source"); | ||
$scope.$parent.pageTitle = "Data Sources"; | ||
|
||
$scope.dataSourceId = $routeParams.dataSourceId; | ||
|
||
if ($scope.dataSourceId == "new") { | ||
$scope.dataSource = new DataSource({options: {}}); | ||
} else { | ||
$scope.dataSource = DataSource.get({id: $routeParams.dataSourceId}); | ||
} | ||
|
||
$scope.$watch('dataSource.id', function(id) { | ||
if (id != $scope.dataSourceId && id !== undefined) { | ||
$location.path('/data_sources/' + id).replace(); | ||
} | ||
}); | ||
}; | ||
|
||
angular.module('redash.controllers') | ||
.controller('DataSourcesCtrl', ['$scope', '$location', 'growl', 'Events', 'DataSource', DataSourcesCtrl]) | ||
.controller('DataSourceCtrl', ['$scope', '$routeParams', '$http', '$location', 'Events', 'DataSource', DataSourceCtrl]) | ||
})(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
var directives = angular.module('redash.directives'); | ||
|
||
// Angular strips data- from the directive, so data-source-form becomes sourceForm... | ||
directives.directive('sourceForm', ['$http', 'growl', function ($http, growl) { | ||
return { | ||
restrict: 'E', | ||
replace: true, | ||
templateUrl: '/views/data_sources/form.html', | ||
scope: { | ||
'dataSource': '=' | ||
}, | ||
link: function ($scope) { | ||
var setType = function(types) { | ||
if ($scope.dataSource.type === undefined) { | ||
$scope.dataSource.type = types[0].type; | ||
return types[0]; | ||
} | ||
|
||
$scope.type = _.find(types, function (t) { | ||
return t.type == $scope.dataSource.type; | ||
}); | ||
}; | ||
|
||
$scope.files = {}; | ||
|
||
$scope.$watchCollection('files', function() { | ||
_.each($scope.files, function(v, k) { | ||
if (v) { | ||
$scope.dataSource.options[k] = v.base64; | ||
} | ||
}); | ||
}); | ||
|
||
$http.get('/api/data_sources/types').success(function (types) { | ||
setType(types); | ||
|
||
$scope.dataSourceTypes = types; | ||
|
||
_.each(types, function (type) { | ||
_.each(type.configuration_schema.properties, function (prop, name) { | ||
if (name == 'password' || name == 'passwd') { | ||
prop.type = 'password'; | ||
} | ||
|
||
if (_.string.endsWith(name, "File")) { | ||
prop.type = 'file'; | ||
} | ||
|
||
prop.required = _.contains(type.configuration_schema.required, name); | ||
}); | ||
}); | ||
}); | ||
|
||
$scope.$watch('dataSource.type', function(current, prev) { | ||
if (prev !== current) { | ||
if (prev !== undefined) { | ||
$scope.dataSource.options = {}; | ||
} | ||
setType($scope.dataSourceTypes); | ||
} | ||
}); | ||
|
||
$scope.saveChanges = function() { | ||
$scope.dataSource.$save(function() { | ||
growl.addSuccessMessage("Saved."); | ||
}, function() { | ||
growl.addErrorMessage("Failed saving."); | ||
}); | ||
} | ||
} | ||
} | ||
}]); | ||
})(); |
Oops, something went wrong.