mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 17:38:54 +00:00
accca51f39
* Web interface to add and delete data sources, without the need to ssh into the server. * Ability to safely delete datasources -- query results from this data sources are deleted, while queries get assigned null datasource. * Updated the BigQuery datasource to use the JSON key file from Google Developer console. Also both BigQuery and the Google Spreadsheets datasource no longer store their key on the filesystem, but rather in the DB. * Minor updates to the Flask Admin.
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
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()
|