Esempio n. 1
0
 def test_interactive_new(self):
     runner = CliRunner()
     pg_i = query_runners.keys().index('pg') + 1
     result = runner.invoke(
         new,
         input="test\n%s\n\n\nexample.com\n\ntestdb\n" % (pg_i,))
     self.assertFalse(result.exception)
     self.assertEqual(result.exit_code, 0)
     self.assertEqual(DataSource.select().count(), 1)
     ds = DataSource.select().first()
     self.assertEqual(ds.name, 'test')
     self.assertEqual(ds.type, 'pg')
     self.assertEqual(ds.options['dbname'], 'testdb')
Esempio n. 2
0
 def test_options_new(self):
     runner = CliRunner()
     result = runner.invoke(
         new, ['test', '--options',
               '{"host": "example.com", "dbname": "testdb"}',
               '--type', 'pg'])
     self.assertFalse(result.exception)
     self.assertEqual(result.exit_code, 0)
     self.assertEqual(DataSource.select().count(), 1)
     ds = DataSource.select().first()
     self.assertEqual(ds.name, 'test')
     self.assertEqual(ds.type, 'pg')
     self.assertEqual(ds.options['host'], 'example.com')
     self.assertEqual(ds.options['dbname'], 'testdb')
Esempio n. 3
0
 def test_bad_type_new(self):
     runner = CliRunner()
     result = runner.invoke(
         new, ['test', '--type', 'wrong'])
     self.assertTrue(result.exception)
     self.assertEqual(result.exit_code, 1)
     self.assertIn('not supported', result.output)
     self.assertEqual(DataSource.select().count(), 0)
Esempio n. 4
0
 def test_options_edit(self):
     self.factory.create_data_source(
         name='test1', type='sqlite',
         options=ConfigurationContainer({"dbpath": "/tmp/test.db"}))
     runner = CliRunner()
     result = runner.invoke(
         edit, ['test1', '--options',
                '{"host": "example.com", "dbname": "testdb"}',
                '--name', 'test2',
                '--type', 'pg'])
     self.assertFalse(result.exception)
     self.assertEqual(result.exit_code, 0)
     self.assertEqual(DataSource.select().count(), 1)
     ds = DataSource.select().first()
     self.assertEqual(ds.name, 'test2')
     self.assertEqual(ds.type, 'pg')
     self.assertEqual(ds.options['host'], 'example.com')
     self.assertEqual(ds.options['dbname'], 'testdb')
Esempio n. 5
0
 def test_connection_bad_delete(self):
     self.factory.create_data_source(
         name='test1', type='sqlite',
         options=ConfigurationContainer({"dbpath": "/tmp/test.db"}))
     runner = CliRunner()
     result = runner.invoke(delete_ds, ['wrong'])
     self.assertTrue(result.exception)
     self.assertEqual(result.exit_code, 1)
     self.assertIn("Couldn't find", result.output)
     self.assertEqual(DataSource.select().count(), 1)
Esempio n. 6
0
 def test_bad_options_new(self):
     runner = CliRunner()
     result = runner.invoke(
         new, ['test', '--options',
               '{"host": 12345, "dbname": "testdb"}',
               '--type', 'pg'])
     self.assertTrue(result.exception)
     self.assertEqual(result.exit_code, 1)
     self.assertIn('invalid configuration', result.output)
     self.assertEqual(DataSource.select().count(), 0)
Esempio n. 7
0
 def test_bad_type_edit(self):
     self.factory.create_data_source(
         name='test1', type='sqlite',
         options=ConfigurationContainer({"dbpath": "/tmp/test.db"}))
     runner = CliRunner()
     result = runner.invoke(
         edit, ['test', '--type', 'wrong'])
     self.assertTrue(result.exception)
     self.assertEqual(result.exit_code, 1)
     self.assertIn('not supported', result.output)
     ds = DataSource.select().first()
     self.assertEqual(ds.type, 'sqlite')
Esempio n. 8
0
 def test_bad_options_edit(self):
     ds = self.factory.create_data_source(
         name='test1', type='sqlite',
         options=ConfigurationContainer({"dbpath": "/tmp/test.db"}))
     runner = CliRunner()
     result = runner.invoke(
         new, ['test', '--options',
               '{"host": 12345, "dbname": "testdb"}',
               '--type', 'pg'])
     self.assertTrue(result.exception)
     self.assertEqual(result.exit_code, 1)
     self.assertIn('invalid configuration', result.output)
     ds = DataSource.select().first()
     self.assertEqual(ds.type, 'sqlite')
     self.assertEqual(ds.options._config, {"dbpath": "/tmp/test.db"})
from base64 import b64encode
import simplejson
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.select(DataSource.id, DataSource.type,
                                DataSource.options):

        if ds.type == 'bigquery':
            options = simplejson.loads(ds.options)

            if 'jsonKeyFile' in options:
                continue

            new_options = {
                'projectId':
                options['projectId'],
                'jsonKeyFile':
                b64encode(
                    simplejson.dumps({
                        'client_email':
                        options['serviceAccount'],
        if "verify" in old_config:
            configuration['verify'] = old_config['verify']

        if "auth" in old_config:
            configuration['username'], configuration['password'] = old_config[
                "auth"]

        data_source.options = json.dumps(configuration)

    elif data_source.type == 'url':
        data_source.options = json.dumps({"url": data_source.options})

    elif data_source.type == 'script':
        data_source.options = json.dumps({"path": data_source.options})

    elif data_source.type == 'mongo':
        data_source.type = 'mongodb'

    else:
        print("[%s] No need to convert type of: %s" %
              (data_source.name, data_source.type))

    print("[%s] New options: %s" % (data_source.name, data_source.options))
    data_source.save(only=data_source.dirty_fields)


if __name__ == '__main__':
    for data_source in DataSource.select(DataSource.id, DataSource.name,
                                         DataSource.type, DataSource.options):
        update(data_source)
from base64 import b64encode
import simplejson
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.select(DataSource.id, DataSource.type, DataSource.options):

        if ds.type == 'bigquery':
            options = simplejson.loads(ds.options)

            if 'jsonKeyFile' in options:
                continue

            new_options = {
                'projectId': options['projectId'],
                'jsonKeyFile': b64encode(simplejson.dumps({
                    'client_email': options['serviceAccount'],
                    'private_key': convert_p12_to_pem(options['privateKey'])
                }))
            }

            ds.options = simplejson.dumps(new_options)
        configuration = {
            "url": old_config["url"]
        }

        if "verify" in old_config:
            configuration['verify'] = old_config['verify']

        if "auth" in old_config:
            configuration['username'], configuration['password'] = old_config["auth"]

        data_source.options = json.dumps(configuration)

    elif data_source.type == 'url':
        data_source.options = json.dumps({"url": data_source.options})

    elif data_source.type == 'script':
        data_source.options = json.dumps({"path": data_source.options})

    elif data_source.type == 'mongo':
        data_source.type = 'mongodb'

    else:
        print "[%s] No need to convert type of: %s" % (data_source.name, data_source.type)

    print "[%s] New options: %s" % (data_source.name, data_source.options)
    data_source.save()


if __name__ == '__main__':
    for data_source in DataSource.select():
        update(data_source)
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.select():

        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)
Esempio n. 14
0
__author__ = 'lior'

from redash.models import DataSource

if __name__ == '__main__':

    for ds in DataSource.select():
        if ds.type == 'elasticsearch':
            ds.type = 'kibana'
            ds.save()
            "url": old_config["url"]
        }

        if "verify" in old_config:
            configuration['verify'] = old_config['verify']

        if "auth" in old_config:
            configuration['username'], configuration['password'] = old_config["auth"]

        data_source.options = json.dumps(configuration)

    elif data_source.type == 'url':
        data_source.options = json.dumps({"url": data_source.options})

    elif data_source.type == 'script':
        data_source.options = json.dumps({"path": data_source.options})

    elif data_source.type == 'mongo':
        data_source.type = 'mongodb'

    else:
        print("[%s] No need to convert type of: %s" % (data_source.name, data_source.type))

    print("[%s] New options: %s" % (data_source.name, data_source.options))
    data_source.save(only=data_source.dirty_fields)


if __name__ == '__main__':
    for data_source in DataSource.select(DataSource.id, DataSource.name, DataSource.type, DataSource.options):
        update(data_source)
__author__ = "lior"

from redash.models import DataSource

if __name__ == "__main__":

    for ds in DataSource.select(DataSource.id, DataSource.type):
        if ds.type == "elasticsearch":
            ds.type = "kibana"
            ds.save(only=ds.dirty_fields)
__author__ = 'lior'

from redash.models import DataSource

if __name__ == '__main__':

    for ds in DataSource.select(DataSource.id, DataSource.type):
        if ds.type == 'elasticsearch':
            ds.type = 'kibana'
            ds.save(only=ds.dirty_fields)
        configuration = {"url": old_config["url"]}

        if "verify" in old_config:
            configuration['verify'] = old_config['verify']

        if "auth" in old_config:
            configuration['username'], configuration['password'] = old_config[
                "auth"]

        data_source.options = json.dumps(configuration)

    elif data_source.type == 'url':
        data_source.options = json.dumps({"url": data_source.options})

    elif data_source.type == 'script':
        data_source.options = json.dumps({"path": data_source.options})

    elif data_source.type == 'mongo':
        data_source.type = 'mongodb'

    else:
        print "[%s] No need to convert type of: %s" % (data_source.name,
                                                       data_source.type)

    print "[%s] New options: %s" % (data_source.name, data_source.options)
    data_source.save()


if __name__ == '__main__':
    for data_source in DataSource.select():
        update(data_source)