Răsfoiți Sursa

[libsentry] Add WITH GRANT option syntax

Romain Rigaux 11 ani în urmă
părinte
comite
01a3b36

+ 30 - 1
desktop/libs/libsentry/gen-py/sentry_policy_service/ttypes.py

@@ -18,6 +18,23 @@ except:
   fastbinary = None
 
 
+class TSentryGrantOption(object):
+  TRUE = 1
+  FALSE = 0
+  UNSET = -1
+
+  _VALUES_TO_NAMES = {
+    1: "TRUE",
+    0: "FALSE",
+    -1: "UNSET",
+  }
+
+  _NAMES_TO_VALUES = {
+    "TRUE": 1,
+    "FALSE": 0,
+    "UNSET": -1,
+  }
+
 
 class TSentryPrivilege(object):
   """
@@ -30,6 +47,7 @@ class TSentryPrivilege(object):
    - action
    - createTime
    - grantorPrincipal
+   - grantOption
   """
 
   thrift_spec = (
@@ -43,9 +61,10 @@ class TSentryPrivilege(object):
     (7, TType.STRING, 'action', None, "", ), # 7
     (8, TType.I64, 'createTime', None, None, ), # 8
     (9, TType.STRING, 'grantorPrincipal', None, None, ), # 9
+    (10, TType.I32, 'grantOption', None,     0, ), # 10
   )
 
-  def __init__(self, privilegeScope=None, serverName=None, dbName=thrift_spec[4][4], tableName=thrift_spec[5][4], URI=thrift_spec[6][4], action=thrift_spec[7][4], createTime=None, grantorPrincipal=None,):
+  def __init__(self, privilegeScope=None, serverName=None, dbName=thrift_spec[4][4], tableName=thrift_spec[5][4], URI=thrift_spec[6][4], action=thrift_spec[7][4], createTime=None, grantorPrincipal=None, grantOption=thrift_spec[10][4],):
     self.privilegeScope = privilegeScope
     self.serverName = serverName
     self.dbName = dbName
@@ -54,6 +73,7 @@ class TSentryPrivilege(object):
     self.action = action
     self.createTime = createTime
     self.grantorPrincipal = grantorPrincipal
+    self.grantOption = grantOption
 
   def read(self, iprot):
     if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
@@ -104,6 +124,11 @@ class TSentryPrivilege(object):
           self.grantorPrincipal = iprot.readString();
         else:
           iprot.skip(ftype)
+      elif fid == 10:
+        if ftype == TType.I32:
+          self.grantOption = iprot.readI32();
+        else:
+          iprot.skip(ftype)
       else:
         iprot.skip(ftype)
       iprot.readFieldEnd()
@@ -146,6 +171,10 @@ class TSentryPrivilege(object):
       oprot.writeFieldBegin('grantorPrincipal', TType.STRING, 9)
       oprot.writeString(self.grantorPrincipal)
       oprot.writeFieldEnd()
+    if self.grantOption is not None:
+      oprot.writeFieldBegin('grantOption', TType.I32, 10)
+      oprot.writeI32(self.grantOption)
+      oprot.writeFieldEnd()
     oprot.writeFieldStop()
     oprot.writeStructEnd()
 

+ 12 - 2
desktop/libs/libsentry/thrift/sentry_policy_service.thrift

@@ -22,13 +22,22 @@
 # Thrift Service that the MetaStore is built on
 #
 
-# include "share/fb303/if/fb303.thrift"
+#include "share/fb303/if/fb303.thrift"
 include "sentry_common_service.thrift"
 
 namespace java org.apache.sentry.provider.db.service.thrift
 namespace php sentry.provider.db.service.thrift
 namespace cpp Apache.Sentry.Provider.Db.Service.Thrift
 
+enum TSentryGrantOption {
+  TRUE = 1,
+  FALSE = 0,
+  # UNSET is used for revoke privilege, the component like 'hive'
+  # didn't support getting grant option, so use UNSET is stand
+  # for revoke both privileges with grant option and without grant
+  # option.
+  UNSET = -1
+}
 
 # Represents a Privilege in transport from the client to the server
 struct TSentryPrivilege {
@@ -39,7 +48,8 @@ struct TSentryPrivilege {
 6: optional string URI = "",
 7: required string action = "",
 8: optional i64 createTime, # Set on server side
-9: optional string grantorPrincipal # Set on server side
+9: optional string grantorPrincipal, # Set on server side
+10: optional TSentryGrantOption grantOption = TSentryGrantOption.FALSE
 }
 
 # TODO can this be deleted? it's not adding value to TAlterSentryRoleAddGroupsRequest