Browse Source

HUE-2845 [desktop] Add optional /desktop/debug/check_config JSON response

This makes it easier to script polling for the config status.
Erick Tryzelaar 10 years ago
parent
commit
e94a1d9

+ 5 - 9
desktop/core/src/desktop/templates/check_config.mako

@@ -24,23 +24,19 @@ from django.utils.translation import ugettext as _
       <div class="alert alert-warn">${_('Potential misconfiguration detected. Fix and restart Hue.')}</div>
       <div class="alert alert-warn">${_('Potential misconfiguration detected. Fix and restart Hue.')}</div>
       <br/>
       <br/>
         <table class="table table-striped">
         <table class="table table-striped">
-      % for confvar, error in error_list:
+      % for error in error_list:
         <tr>
         <tr>
             <td width="15%">
             <td width="15%">
                 <code>
                 <code>
-                % if isinstance(confvar, str):
-                  ${confvar | n}
-                % else:
-                  ${confvar.get_fully_qualifying_key()}
-                % endif
+                ${error['name'] | n}
               </code>
               </code>
             </td>
             </td>
             <td>
             <td>
               ## Doesn't make sense to print the value of a BoundContainer
               ## Doesn't make sense to print the value of a BoundContainer
-              % if type(confvar) is BoundConfig:
-                ${_('Current value:')} <code>${confvar.get()}</code><br/>
+              % if 'value' in error:
+                ${_('Current value:')} <code>${error['value']}</code><br/>
               % endif
               % endif
-              ${error | n}
+              ${error['message'] | n}
             </td>
             </td>
         </tr>
         </tr>
       % endfor
       % endfor

+ 21 - 9
desktop/core/src/desktop/views.py

@@ -42,8 +42,8 @@ import desktop.log.log_buffer
 from desktop.api import massaged_tags_for_json, massaged_documents_for_json,\
 from desktop.api import massaged_tags_for_json, massaged_documents_for_json,\
   _get_docs
   _get_docs
 from desktop.lib import django_mako
 from desktop.lib import django_mako
-from desktop.lib.conf import GLOBAL_CONFIG
-from desktop.lib.django_util import login_notrequired, render_json, render
+from desktop.lib.conf import GLOBAL_CONFIG, BoundConfig
+from desktop.lib.django_util import JsonResponse, login_notrequired, render_json, render
 from desktop.lib.i18n import smart_str
 from desktop.lib.i18n import smart_str
 from desktop.lib.paths import get_desktop_root
 from desktop.lib.paths import get_desktop_root
 from desktop.lib.thread_util import dump_traceback
 from desktop.lib.thread_util import dump_traceback
@@ -431,7 +431,16 @@ def _get_config_errors(request, cache=True):
         continue
         continue
 
 
       try:
       try:
-        error_list.extend(validator(request.user))
+        for confvar, error in validator(request.user):
+          error = {
+            'name': confvar.get_fully_qualifying_key() if isinstance(confvar, BoundConfig) else confvar,
+            'message': error,
+          }
+
+          if isinstance(confvar, BoundConfig):
+            error['value'] = confvar.get_fully_qualifying_key()
+
+          error_list.append(error)
       except Exception, ex:
       except Exception, ex:
         LOG.exception("Error in config validation by %s: %s" % (module.nice_name, ex))
         LOG.exception("Error in config validation by %s: %s" % (module.nice_name, ex))
     _CONFIG_ERROR_LIST = error_list
     _CONFIG_ERROR_LIST = error_list
@@ -443,12 +452,15 @@ def check_config(request):
   if not request.user.is_superuser:
   if not request.user.is_superuser:
     return HttpResponse(_("You must be a superuser."))
     return HttpResponse(_("You must be a superuser."))
 
 
-  conf_dir = os.path.realpath(os.getenv("HUE_CONF_DIR", get_desktop_root("conf")))
-  return render('check_config.mako', request, {
-                  'error_list': _get_config_errors(request, cache=False),
-                  'conf_dir': conf_dir
-              },
-              force_template=True)
+  context = {
+    'conf_dir': os.path.realpath(os.getenv("HUE_CONF_DIR", get_desktop_root("conf"))),
+    'error_list': _get_config_errors(request, cache=False),
+  }
+
+  if request.GET.get('format') == 'json':
+    return JsonResponse()
+  else:
+    return render('check_config.mako', request, context, force_template=True)
 
 
 
 
 def check_config_ajax(request):
 def check_config_ajax(request):