Ver Fonte

HUE-1638 [core] Secure database connection

Abraham Elmahrek há 12 anos atrás
pai
commit
8c33d4ee5c

+ 1 - 0
desktop/conf.dist/hue.ini

@@ -183,6 +183,7 @@
     ## user=
     ## password=
     ## name=desktop/desktop.db
+    ## options={}
 
   # Configuration options for specifying the Desktop session.
   # For more info, see https://docs.djangoproject.com/en/1.4/topics/http/sessions/

+ 1 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -189,6 +189,7 @@
     ## user=
     ## password=
     ## name=desktop/desktop.db
+    ## options={}
 
   # Configuration options for specifying the Desktop session.
   # For more info, see https://docs.djangoproject.com/en/1.4/topics/http/sessions/

+ 9 - 2
desktop/core/src/desktop/conf.py

@@ -21,8 +21,9 @@ import stat
 
 from django.utils.translation import ugettext_lazy as _
 
-from desktop.lib.conf import Config, ConfigSection, UnspecifiedConfigSection
-from desktop.lib.conf import coerce_bool, coerce_csv, validate_path
+from desktop.lib.conf import Config, ConfigSection, UnspecifiedConfigSection,\
+                             coerce_bool, coerce_csv, coerce_json_dict,\
+                             validate_path
 from desktop.lib.i18n import force_unicode
 from desktop.lib.paths import get_desktop_root
 
@@ -220,6 +221,12 @@ DATABASE = ConfigSection(
       type=int,
       default=0,
     ),
+    OPTIONS=Config(
+      key='options',
+      help=_('Database options to send to the server when connecting.'),
+      type=coerce_json_dict,
+      default='{}'
+    )
   )
 )
 

+ 8 - 1
desktop/core/src/desktop/lib/conf.py

@@ -68,6 +68,7 @@ pytype = type
 from desktop.lib.paths import get_desktop_root, get_build_dir
 
 import configobj
+import json
 import logging
 import os
 import textwrap
@@ -81,7 +82,7 @@ GLOBAL_CONFIG = None
 
 LOG = logging.getLogger(__name__)
 
-__all__ = ["UnspecifiedConfigSection", "ConfigSection", "Config", "load_confs", "coerce_bool", "coerce_csv"]
+__all__ = ["UnspecifiedConfigSection", "ConfigSection", "Config", "load_confs", "coerce_bool", "coerce_csv", "coerce_json_dict"]
 
 class BoundConfig(object):
   def __init__(self, config, bind_to, grab_key=_ANONYMOUS, prefix=''):
@@ -619,6 +620,12 @@ def coerce_csv(value):
     return value
   raise Exception("Could not coerce %r to csv array." % value)
 
+def coerce_json_dict(value):
+  if isinstance(value, basestring):
+    return json.loads(value)
+  elif isinstance(value, dict):
+    return value
+  raise Exception("Could not coerce %r to json dictionary." % value)
 
 def validate_path(confvar, is_dir=None, fs=os.path, message='Path does not exist on the filesystem.'):
   """

+ 1 - 0
desktop/core/src/desktop/settings.py

@@ -252,6 +252,7 @@ else:
     "PASSWORD" : desktop.conf.DATABASE.PASSWORD.get(),
     "HOST" : desktop.conf.DATABASE.HOST.get(),
     "PORT" : str(desktop.conf.DATABASE.PORT.get()),
+    "OPTIONS": desktop.conf.DATABASE.OPTIONS.get(),
     # DB used for tests
     "TEST_NAME" : get_desktop_root('desktop-test.db')
   }