forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read settings from environment variables instead of a settings file.
This is mostly done to make it easier to run re:dash on Heroku but should be convenient in other platforms too.
- Loading branch information
Showing
4 changed files
with
72 additions
and
31 deletions.
There are no files selected for viewing
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,44 @@ | ||
import os | ||
import urlparse | ||
|
||
|
||
def parse_db_url(url): | ||
url_parts = urlparse.urlparse(url) | ||
connection = { | ||
'engine': 'peewee.PostgresqlDatabase', | ||
} | ||
|
||
if url_parts.hostname and not url_parts.path: | ||
connection['name'] = url_parts.hostname | ||
else: | ||
connection['name'] = url_parts.path[1:] | ||
connection['host'] = url_parts.hostname | ||
connection['port'] = url_parts.port | ||
connection['user'] = url_parts.username | ||
connection['password'] = url_parts.password | ||
|
||
return connection | ||
|
||
REDIS_URL = os.environ.get('REDASH_REDIS_URL', "redis://localhost:6379") | ||
|
||
# "pg", "graphite" or "mysql" | ||
CONNECTION_ADAPTER = os.environ.get("REDASH_CONNECTION_ADAPTER", "pg") | ||
# Connection string for the database that is used to run queries against. Examples: | ||
# -- mysql: CONNECTION_STRING = "Server=;User=;Pwd=;Database=" | ||
# -- pg: CONNECTION_STRING = "user= password= host= port=5439 dbname=" | ||
# -- graphite: CONNECTION_STRING = {'url': 'https://graphite.yourcompany.com', 'auth': ('user', 'password'), 'verify': True} | ||
CONNECTION_STRING = os.environ.get("REDASH_CONNECTION_STRING", "user= password= host= port=5439 dbname=") | ||
|
||
# Connection settings for re:dash's own database (where we store the queries, results, etc) | ||
DATABASE_CONFIG = parse_db_url(os.environ.get("REDASH_DATABASE_URL", "postgresql://postgres")) | ||
|
||
# Google Apps domain to allow access from; any user with email in this Google Apps will be allowed | ||
# access | ||
GOOGLE_APPS_DOMAIN = os.environ.get("REDASH_GOOGLE_APPS_DOMAIN", "") | ||
# Email addresses of admin users (comma separated) | ||
ADMINS = os.environ.get("REDASH_ADMINS", '').split(',') | ||
STATIC_ASSETS_PATH = os.environ.get("REDASH_STATIC_ASSETS_PATH", "../rd_ui/dist/") | ||
WORKERS_COUNT = int(os.environ.get("REDASH_WORKERS_COUNT", "2")) | ||
COOKIE_SECRET = os.environ.get("REDASH_COOKIE_SECRET", "c292a0a3aa32397cdb050e233733900f") | ||
LOG_LEVEL = os.environ.get("REDASH_LOG_LEVEL", "INFO") | ||
ANALYTICS = os.environ.get("REDASH_ANALYTICS", "") |
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,27 @@ | ||
from redash import settings as settings | ||
from unittest import TestCase | ||
|
||
|
||
class TestDatabaseUrlParser(TestCase): | ||
def test_only_database_name(self): | ||
config = settings.parse_db_url("postgresql://postgres") | ||
self.assertEquals(config['name'], 'postgres') | ||
|
||
def test_host_and_database_name(self): | ||
config = settings.parse_db_url("postgresql://localhost/postgres") | ||
self.assertEquals(config['name'], 'postgres') | ||
self.assertEquals(config['host'], 'localhost') | ||
|
||
def test_host_with_port_and_database_name(self): | ||
config = settings.parse_db_url("postgresql://localhost:5432/postgres") | ||
self.assertEquals(config['name'], 'postgres') | ||
self.assertEquals(config['host'], 'localhost') | ||
self.assertEquals(config['port'], 5432) | ||
|
||
def test_full_url(self): | ||
config = settings.parse_db_url("postgresql://user:pass@localhost:5432/postgres") | ||
self.assertEquals(config['name'], 'postgres') | ||
self.assertEquals(config['host'], 'localhost') | ||
self.assertEquals(config['port'], 5432) | ||
self.assertEquals(config['user'], 'user') | ||
self.assertEquals(config['password'], 'pass') |