Эх сурвалжийг харах

HUE-3667 [sentry] Support TListSentryPrivilegesByAuthRequest v2

Romain Rigaux 9 жил өмнө
parent
commit
54771d9

+ 2 - 1
apps/security/src/security/api/sentry.py

@@ -352,12 +352,13 @@ def list_sentry_privileges_by_authorizable(request):
 
   try:
     groups = [request.POST['groupName']] if request.POST['groupName'] else None
+    serviceName = request.POST['server']
     authorizableSet = [json.loads(request.POST['authorizableHierarchy'])]
     component = request.POST['component']
 
     _privileges = []
 
-    for authorizable, roles in get_api(request.user, component).list_sentry_privileges_by_authorizable(authorizableSet=authorizableSet, groups=groups):
+    for authorizable, roles in get_api(request.user, component).list_sentry_privileges_by_authorizable(serviceName=serviceName, authorizableSet=authorizableSet, groups=groups):
       for role, privileges in roles.iteritems():
         for privilege in privileges:
           privilege['roleName'] = role

+ 11 - 4
apps/security/src/security/static/security/js/sentry.ko.js

@@ -1152,9 +1152,15 @@ var SentryViewModel = function (initial) {
     if (optionalPath != null) {
       var paths = optionalPath.split(/[.]/);
 
-      if (paths[0]) { authorizables.push({'type': 'db', 'name': paths[0]}); }
-      if (paths[1]) { authorizables.push({'type': 'table', 'name': paths[1]}); }
-      if (paths[2]) { authorizables.push({'type': 'column', 'name': paths[2]}); }
+      if (paths[0]) {
+        authorizables.push({'type': 'db', 'name': paths[0]});
+      }
+      if (paths[1]) {
+        authorizables.push({'type': 'table', 'name': paths[1]});
+      }
+      if (paths[2]) {
+        authorizables.push({'type': 'column', 'name': paths[2]});
+      }
     } else {
       authorizables.push({'type': 'column', 'name': self.assist.db()});
       authorizables.push({'type': 'table', 'name': self.assist.table()});
@@ -1222,7 +1228,8 @@ var SentryViewModel = function (initial) {
       type: "POST",
       url: "/security/api/sentry/list_sentry_privileges_by_authorizable",
       data: {
-        groupName: $('#selectedGroup').val(),
+        server: self.server(),
+    	groupName: $('#selectedGroup').val(),
         roleSet: ko.mapping.toJSON({all: true, roles: []}),
         authorizableHierarchy: ko.mapping.toJSON(_create_authorizable_from_ko(_path)),
         component: self.component()

+ 2 - 2
desktop/libs/libsentry/src/libsentry/api2.py

@@ -162,8 +162,8 @@ class SentryApi(object):
       raise SentryException(response)
 
   @ha_error_handler
-  def list_sentry_privileges_by_authorizable(self, authorizableSet, groups=None, roleSet=None):
-    response = self.client.list_sentry_privileges_by_authorizable(authorizableSet, groups, roleSet)
+  def list_sentry_privileges_by_authorizable(self, serviceName, authorizableSet, groups=None, roleSet=None):
+    response = self.client.list_sentry_privileges_by_authorizable(serviceName, authorizableSet, groups, roleSet)
 
     if response.status.value != 0:
       raise SentryException(response)

+ 4 - 3
desktop/libs/libsentry/src/libsentry/client2.py

@@ -175,10 +175,11 @@ class SentryClient(object):
     return self.client.list_sentry_privileges_for_provider(request)
 
 
-  def list_sentry_privileges_by_authorizable(self, authorizableSet, groups=None, roleSet=None):
-    authorizableSet = [TAuthorizable(**authorizable) for authorizable in authorizableSet]
+  def list_sentry_privileges_by_authorizable(self, serviceName, authorizableSet, groups=None, roleSet=None):
+    authorizableSet = ['%s->%s' % (_auth['type'], _auth['name']) for _authSet in authorizableSet for _auth in _authSet['authorizables']]
+
     if roleSet is not None:
       roleSet = TSentryActiveRoleSet(**roleSet)
 
-    request = TListSentryPrivilegesByAuthRequest(requestorUserName=self.username, component=self.component, authorizableSet=authorizableSet, groups=groups, roleSet=roleSet)
+    request = TListSentryPrivilegesByAuthRequest(requestorUserName=self.username, component=self.component, serviceName=serviceName, authorizablesSet=set(authorizableSet), groups=groups, roleSet=roleSet)
     return self.client.list_sentry_privileges_by_authorizable(request)