|
@@ -27,6 +27,11 @@ from useradmin.models import User
|
|
|
from desktop.auth.backend import is_admin
|
|
from desktop.auth.backend import is_admin
|
|
|
from desktop.conf import DEFAULT_USER, ENABLE_ORGANIZATIONS
|
|
from desktop.conf import DEFAULT_USER, ENABLE_ORGANIZATIONS
|
|
|
|
|
|
|
|
|
|
+from aws.conf import is_raz_s3
|
|
|
|
|
+from aws.s3.s3fs import get_s3_home_directory
|
|
|
|
|
+
|
|
|
|
|
+from azure.conf import is_raz_abfs
|
|
|
|
|
+from azure.abfs.__init__ import get_home_dir_for_abfs
|
|
|
|
|
|
|
|
if sys.version_info[0] > 2:
|
|
if sys.version_info[0] > 2:
|
|
|
from urllib.parse import urlparse as lib_urlparse
|
|
from urllib.parse import urlparse as lib_urlparse
|
|
@@ -200,9 +205,34 @@ class ProxyFS(object):
|
|
|
self._get_fs(path).create(path, *args, **kwargs)
|
|
self._get_fs(path).create(path, *args, **kwargs)
|
|
|
|
|
|
|
|
def create_home_dir(self, home_path=None):
|
|
def create_home_dir(self, home_path=None):
|
|
|
|
|
+ """
|
|
|
|
|
+ Initially home_path will have path value for HDFS and if it is configured in Hue, try creating the user home dir for it first.
|
|
|
|
|
+ Then we check if S3/ABFS is configured in Hue via RAZ. If yes, try creating user home dir for them next.
|
|
|
|
|
+ """
|
|
|
if home_path is None:
|
|
if home_path is None:
|
|
|
home_path = self.get_home_dir()
|
|
home_path = self.get_home_dir()
|
|
|
- self._get_fs(home_path).create_home_dir(home_path)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ self._get_fs(home_path).create_home_dir(home_path)
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ LOG.debug('Error creating HDFS home directory for path %s : %s' % (home_path, str(e)))
|
|
|
|
|
+
|
|
|
|
|
+ # Get the new home_path for S3/ABFS when RAZ is enabled.
|
|
|
|
|
+ if is_raz_s3():
|
|
|
|
|
+ home_path = get_s3_home_directory(User.objects.get(username=self.getuser()))
|
|
|
|
|
+ elif is_raz_abfs():
|
|
|
|
|
+ home_path = get_home_dir_for_abfs(User.objects.get(username=self.getuser()))
|
|
|
|
|
+
|
|
|
|
|
+ # Try getting user from the request and create home dirs. This helps when Hue admin is trying to create the dir for other users.
|
|
|
|
|
+ # That way only Hue admin needs authorization to create for all Hue users and not each individual user.
|
|
|
|
|
+ # If normal users also have authorization, then they can also create the dir for themselves if they want.
|
|
|
|
|
+ from crequest.middleware import CrequestMiddleware
|
|
|
|
|
+ request = CrequestMiddleware.get_request()
|
|
|
|
|
+ username = request.user.username if request and hasattr(request, 'user') and request.user.is_authenticated else self.getuser()
|
|
|
|
|
+
|
|
|
|
|
+ if is_raz_s3() or is_raz_abfs():
|
|
|
|
|
+ fs = self.do_as_user(username, self._get_fs, home_path)
|
|
|
|
|
+ fs.create_home_dir(home_path)
|
|
|
|
|
|
|
|
def chown(self, path, *args, **kwargs):
|
|
def chown(self, path, *args, **kwargs):
|
|
|
self._get_fs(path).chown(path, *args, **kwargs)
|
|
self._get_fs(path).chown(path, *args, **kwargs)
|