Bläddra i källkod

HUE-8782 [hbase] Add back decorator to Thrift calls to set the doAs header

Romain 6 år sedan
förälder
incheckning
e85e1fda2b
1 ändrade filer med 82 tillägg och 0 borttagningar
  1. 82 0
      apps/hbase/gen-py/hbased/Hbase.py

+ 82 - 0
apps/hbase/gen-py/hbased/Hbase.py

@@ -3,6 +3,8 @@
 #
 # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 #
+# Warning: module edited below.
+#
 #  options string: py:new_style
 #
 
@@ -17,6 +19,43 @@ try:
 except:
   fastbinary = None
 
+from django.utils.functional import wraps
+
+
+### Do as / Impersonation support.
+### This should be put back if rerenerating the Thrift.
+### As well as all the @do_as in Client.
+
+import logging
+
+from django.utils.encoding import smart_str
+from hbase.hbase_site import is_impersonation_enabled
+
+LOG = logging.getLogger(__name__)
+
+
+def do_as(func):
+  def decorate(*args, **kwargs):
+    self = args[0]
+    username = kwargs.pop('doas')
+
+    try:
+      if is_impersonation_enabled():
+        if hasattr(self._oprot.trans, 'TFramedTransport'):
+          trans_client = self._oprot.trans._TFramedTransport__trans
+        else:
+          trans_client = self._oprot.trans._TBufferedTransport__trans
+
+        trans_client.setCustomHeaders({'doAs': username})
+
+    except AttributeError, e:
+      LOG.error('Could not set doAs parameter: %s' % smart_str(e))
+
+    return func(*args, **kwargs)
+  return wraps(func)(decorate)
+
+###
+
 
 class Iface(object):
   def enableTable(self, tableName):
@@ -620,6 +659,7 @@ class Client(Iface):
       self._oprot = oprot
     self._seqid = 0
 
+  @do_as
   def enableTable(self, tableName):
     """
     Brings a table on-line (enables it)
@@ -653,6 +693,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def disableTable(self, tableName):
     """
     Disables a table (takes it off-line) If it is being served, the master
@@ -687,6 +728,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def isTableEnabled(self, tableName):
     """
     @return true if table is on-line
@@ -722,6 +764,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "isTableEnabled failed: unknown result")
 
+  @do_as
   def compact(self, tableNameOrRegionName):
     """
     Parameters:
@@ -753,6 +796,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def majorCompact(self, tableNameOrRegionName):
     """
     Parameters:
@@ -784,6 +828,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def getTableNames(self):
     """
     List all the userspace tables.
@@ -817,6 +862,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getTableNames failed: unknown result")
 
+  @do_as
   def getColumnDescriptors(self, tableName):
     """
     List all the column families assoicated with a table.
@@ -854,6 +900,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getColumnDescriptors failed: unknown result")
 
+  @do_as
   def getTableRegions(self, tableName):
     """
     List the regions associated with a table.
@@ -891,6 +938,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getTableRegions failed: unknown result")
 
+  @do_as
   def createTable(self, tableName, columnFamilies):
     """
     Create a table with the specified column families.  The name
@@ -937,6 +985,7 @@ class Client(Iface):
       raise result.exist
     return
 
+  @do_as
   def deleteTable(self, tableName):
     """
     Deletes a table
@@ -973,6 +1022,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def get(self, tableName, row, column, attributes):
     """
     Get a single TCell for the specified table, row, and column at the
@@ -1017,6 +1067,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "get failed: unknown result")
 
+  @do_as
   def getVer(self, tableName, row, column, numVersions, attributes):
     """
     Get the specified number of versions for the specified table,
@@ -1063,6 +1114,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getVer failed: unknown result")
 
+  @do_as
   def getVerTs(self, tableName, row, column, timestamp, numVersions, attributes):
     """
     Get the specified number of versions for the specified table,
@@ -1112,6 +1164,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getVerTs failed: unknown result")
 
+  @do_as
   def getRow(self, tableName, row, attributes):
     """
     Get all the data for the specified table and row at the latest
@@ -1154,6 +1207,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getRow failed: unknown result")
 
+  @do_as
   def getRowWithColumns(self, tableName, row, columns, attributes):
     """
     Get the specified columns for the specified table and row at the latest
@@ -1198,6 +1252,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getRowWithColumns failed: unknown result")
 
+  @do_as
   def getRowTs(self, tableName, row, timestamp, attributes):
     """
     Get all the data for the specified table and row at the specified
@@ -1242,6 +1297,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getRowTs failed: unknown result")
 
+  @do_as
   def getRowWithColumnsTs(self, tableName, row, columns, timestamp, attributes):
     """
     Get the specified columns for the specified table and row at the specified
@@ -1288,6 +1344,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getRowWithColumnsTs failed: unknown result")
 
+  @do_as
   def getRows(self, tableName, rows, attributes):
     """
     Get all the data for the specified table and rows at the latest
@@ -1330,6 +1387,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getRows failed: unknown result")
 
+  @do_as
   def getRowsWithColumns(self, tableName, rows, columns, attributes):
     """
     Get the specified columns for the specified table and rows at the latest
@@ -1374,6 +1432,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getRowsWithColumns failed: unknown result")
 
+  @do_as
   def getRowsTs(self, tableName, rows, timestamp, attributes):
     """
     Get all the data for the specified table and rows at the specified
@@ -1418,6 +1477,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getRowsTs failed: unknown result")
 
+  @do_as
   def getRowsWithColumnsTs(self, tableName, rows, columns, timestamp, attributes):
     """
     Get the specified columns for the specified table and rows at the specified
@@ -1464,6 +1524,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getRowsWithColumnsTs failed: unknown result")
 
+  @do_as
   def mutateRow(self, tableName, row, mutations, attributes):
     """
     Apply a series of mutations (updates/deletes) to a row in a
@@ -1508,6 +1569,7 @@ class Client(Iface):
       raise result.ia
     return
 
+  @do_as
   def mutateRowTs(self, tableName, row, mutations, timestamp, attributes):
     """
     Apply a series of mutations (updates/deletes) to a row in a
@@ -1554,6 +1616,7 @@ class Client(Iface):
       raise result.ia
     return
 
+  @do_as
   def mutateRows(self, tableName, rowBatches, attributes):
     """
     Apply a series of batches (each a series of mutations on a single row)
@@ -1596,6 +1659,7 @@ class Client(Iface):
       raise result.ia
     return
 
+  @do_as
   def mutateRowsTs(self, tableName, rowBatches, timestamp, attributes):
     """
     Apply a series of batches (each a series of mutations on a single row)
@@ -1640,6 +1704,7 @@ class Client(Iface):
       raise result.ia
     return
 
+  @do_as
   def atomicIncrement(self, tableName, row, column, value):
     """
     Atomically increment the column value specified.  Returns the next value post increment.
@@ -1683,6 +1748,7 @@ class Client(Iface):
       raise result.ia
     raise TApplicationException(TApplicationException.MISSING_RESULT, "atomicIncrement failed: unknown result")
 
+  @do_as
   def deleteAll(self, tableName, row, column, attributes):
     """
     Delete all cells that match the passed row and column.
@@ -1722,6 +1788,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def deleteAllTs(self, tableName, row, column, timestamp, attributes):
     """
     Delete all cells that match the passed row and column and whose
@@ -1764,6 +1831,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def deleteAllRow(self, tableName, row, attributes):
     """
     Completely delete the row's cells.
@@ -1801,6 +1869,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def increment(self, increment):
     """
     Increment a cell by the ammount.
@@ -1837,6 +1906,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def incrementRows(self, increments):
     """
     Parameters:
@@ -1868,6 +1938,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def deleteAllRowTs(self, tableName, row, timestamp, attributes):
     """
     Completely delete the row's cells marked with a timestamp
@@ -1908,6 +1979,7 @@ class Client(Iface):
       raise result.io
     return
 
+  @do_as
   def scannerOpenWithScan(self, tableName, scan, attributes):
     """
     Get a scanner on the current table, using the Scan instance
@@ -1948,6 +2020,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "scannerOpenWithScan failed: unknown result")
 
+  @do_as
   def scannerOpen(self, tableName, startRow, columns, attributes):
     """
     Get a scanner on the current table starting at the specified row and
@@ -1995,6 +2068,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "scannerOpen failed: unknown result")
 
+  @do_as
   def scannerOpenWithStop(self, tableName, startRow, stopRow, columns, attributes):
     """
     Get a scanner on the current table starting and stopping at the
@@ -2046,6 +2120,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "scannerOpenWithStop failed: unknown result")
 
+  @do_as
   def scannerOpenWithPrefix(self, tableName, startAndPrefix, columns, attributes):
     """
     Open a scanner for a given prefix.  That is all rows will have the specified
@@ -2090,6 +2165,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "scannerOpenWithPrefix failed: unknown result")
 
+  @do_as
   def scannerOpenTs(self, tableName, startRow, columns, timestamp, attributes):
     """
     Get a scanner on the current table starting at the specified row and
@@ -2140,6 +2216,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "scannerOpenTs failed: unknown result")
 
+  @do_as
   def scannerOpenWithStopTs(self, tableName, startRow, stopRow, columns, timestamp, attributes):
     """
     Get a scanner on the current table starting and stopping at the
@@ -2194,6 +2271,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "scannerOpenWithStopTs failed: unknown result")
 
+  @do_as
   def scannerGet(self, id):
     """
     Returns the scanner's current row value and advances to the next
@@ -2240,6 +2318,7 @@ class Client(Iface):
       raise result.ia
     raise TApplicationException(TApplicationException.MISSING_RESULT, "scannerGet failed: unknown result")
 
+  @do_as
   def scannerGetList(self, id, nbRows):
     """
     Returns, starting at the scanner's current row value nbRows worth of
@@ -2288,6 +2367,7 @@ class Client(Iface):
       raise result.ia
     raise TApplicationException(TApplicationException.MISSING_RESULT, "scannerGetList failed: unknown result")
 
+  @do_as
   def scannerClose(self, id):
     """
     Closes the server-state associated with an open scanner.
@@ -2325,6 +2405,7 @@ class Client(Iface):
       raise result.ia
     return
 
+  @do_as
   def getRowOrBefore(self, tableName, row, family):
     """
     Get the row just before the specified one.
@@ -2366,6 +2447,7 @@ class Client(Iface):
       raise result.io
     raise TApplicationException(TApplicationException.MISSING_RESULT, "getRowOrBefore failed: unknown result")
 
+  @do_as
   def getRegionInfo(self, row):
     """
     Get the regininfo for the specified row. It scans