Просмотр исходного кода

HUE-2975 [core] Only register S3FileUploadHandler is S3 is enabled

Jenny Kim 9 лет назад
Родитель
Сommit
d55758d1c5
1 измененных файлов с 19 добавлено и 10 удалено
  1. 19 10
      desktop/core/src/desktop/settings.py

+ 19 - 10
desktop/core/src/desktop/settings.py

@@ -29,12 +29,12 @@ from guppy import hpy
 
 from django.utils.translation import ugettext_lazy as _
 
-import desktop.conf
-import desktop.log
 import desktop.redaction
 from desktop.lib.paths import get_desktop_root
 from desktop.lib.python_util import force_dict_to_strings
 
+from aws.conf import is_default_configured as is_s3_enabled
+
 
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.dirname(__file__)), '..', '..', '..'))
@@ -228,14 +228,6 @@ LOGOUT_REDIRECT_URL = "/" # For djangosaml2 bug.
 
 PYLINTRC = get_desktop_root('.pylintrc')
 
-# Insert our custom upload handlers
-FILE_UPLOAD_HANDLERS = (
-  'aws.s3.upload.S3FileUploadHandler',
-  'hadoop.fs.upload.HDFSfileUploadHandler',
-  'django.core.files.uploadhandler.MemoryFileUploadHandler',
-  'django.core.files.uploadhandler.TemporaryFileUploadHandler',
-)
-
 # Custom CSRF Failure View
 CSRF_FAILURE_VIEW = 'desktop.views.csrf_failure'
 
@@ -440,6 +432,23 @@ if desktop.conf.SECURE_PROXY_SSL_HEADER.get():
 if 'useradmin' in [app.name for app in appmanager.DESKTOP_APPS]:
   MIDDLEWARE_CLASSES.append('useradmin.middleware.LastActivityMiddleware')
 
+################################################################
+# Register file upload handlers
+# This section must go after the desktop lib modules are loaded
+################################################################
+
+# Insert our custom upload handlers
+file_upload_handlers = [
+    'hadoop.fs.upload.HDFSfileUploadHandler',
+    'django.core.files.uploadhandler.MemoryFileUploadHandler',
+    'django.core.files.uploadhandler.TemporaryFileUploadHandler',
+]
+
+if is_s3_enabled():
+  file_upload_handlers.insert(0, 'aws.s3.upload.S3FileUploadHandler')
+
+FILE_UPLOAD_HANDLERS = tuple(file_upload_handlers)
+
 ############################################################
 
 # Necessary for South to not fuzz with tests.  Fixed in South 0.7.1