瀏覽代碼

HUE-2955 [desktop] Error if the configured SSL certificate/key files do not exist

krish 10 年之前
父節點
當前提交
15dc487678
共有 2 個文件被更改,包括 11 次插入0 次删除
  1. 6 0
      desktop/core/src/desktop/conf.py
  2. 5 0
      desktop/core/src/desktop/settings.py

+ 6 - 0
desktop/core/src/desktop/conf.py

@@ -52,6 +52,10 @@ def coerce_port(port):
   else:
     return port
 
+def coerce_file(path):
+  if path and not os.path.isfile(path):
+    raise Exception('File %s does not exist.' % path)
+  return path
 
 def coerce_password_from_script(script):
   p = subprocess.Popen(script, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -100,11 +104,13 @@ HTTP_ALLOWED_METHODS = Config(
 SSL_CERTIFICATE = Config(
   key="ssl_certificate",
   help=_("Filename of SSL Certificate"),
+  type=coerce_file,
   default=None)
 
 SSL_PRIVATE_KEY = Config(
   key="ssl_private_key",
   help=_("Filename of SSL RSA Private Key"),
+  type=coerce_file,
   default=None)
 
 SSL_CIPHER_LIST = Config(

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

@@ -34,6 +34,7 @@ import desktop.redaction
 
 from desktop.lib.paths import get_desktop_root
 from desktop.lib.python_util import force_dict_to_strings
+from django.utils.translation import ugettext_lazy as _
 
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
@@ -426,6 +427,10 @@ os.environ['KRB5CCNAME'] = desktop.conf.KERBEROS.CCACHE_PATH.get()
 if desktop.conf.SSL_CACERTS.get() and os.environ.get('REQUESTS_CA_BUNDLE') is None:
   os.environ['REQUESTS_CA_BUNDLE'] = desktop.conf.SSL_CACERTS.get()
 
+# Preventing local build failure by not validating the default value of REQUESTS_CA_BUNDLE
+if os.environ.get('REQUESTS_CA_BUNDLE') and os.environ.get('REQUESTS_CA_BUNDLE') != desktop.conf.SSL_CACERTS.config.default and not os.path.isfile(os.environ['REQUESTS_CA_BUNDLE']):
+  raise Exception(_('SSL Certificate pointed by REQUESTS_CA_BUNDLE does not exist: %s') % os.environ['REQUESTS_CA_BUNDLE'])
+
 # Memory
 if desktop.conf.MEMORY_PROFILER.get():
   MEMORY_PROFILER = hpy()