
from kazoo.client import KazooClient
from libzookeeper.conf import PRINCIPAL_NAME


def get_children_data(ensemble, namespace, read_only=True):
  zk = KazooClient(hosts=ensemble, read_only=read_only, sasl_server_principal=PRINCIPAL_NAME.get())

  zk.start()

  children_data = []

  children = zk.get_children(namespace)

  for node in children:
    data, stat = zk.get("%s/%s" % (namespace, node))
    children_data.append(data)

  zk.stop()
  
  return children_data


from kazoo.client import KazooClient

from hadoop import cluster
from desktop.lib.exceptions_renderable import PopupException

from libzookeeper.conf import PRINCIPAL_NAME


def get_children_data(ensemble, namespace, read_only=True):
  hdfs = cluster.get_hdfs()
  if hdfs is None:
    raise PopupException(_('No [hdfs] configured in hue.ini.'))

  if hdfs.security_enabled:
    sasl_server_principal = PRINCIPAL_NAME.get()
  else:
    sasl_server_principal = None

  zk = KazooClient(hosts=ensemble, read_only=read_only, sasl_server_principal=sasl_server_principal)

  zk.start()

  children_data = []

  children = zk.get_children(namespace)

  for node in children:
    data, stat = zk.get("%s/%s" % (namespace, node))
    children_data.append(data)

  zk.stop()

  return children_data

Enable Kerberos automatically based on HDFS security
[libzookeeper] Enable Kerberos automatically based on HDFS security

We don't need another property that way and Kerberos is a all or nothing
setup.
Even if HDFS is not used in Hue, the default hue.ini has security set
to false.

  
  from kazoo.client import KazooClient
+ 
+ from hadoop import cluster
+ from desktop.lib.exceptions_renderable import PopupException
+ 
  from libzookeeper.conf import PRINCIPAL_NAME
  
  
  def get_children_data(ensemble, namespace, read_only=True):
+   hdfs = cluster.get_hdfs()
+   if hdfs is None:
+     raise PopupException(_('No [hdfs] configured in hue.ini.'))
+ 
+   if hdfs.security_enabled:
+     sasl_server_principal = PRINCIPAL_NAME.get()
+   else:
+     sasl_server_principal = None
+ 
-   zk = KazooClient(hosts=ensemble, read_only=read_only, sasl_server_principal=PRINCIPAL_NAME.get())
+   zk = KazooClient(hosts=ensemble, read_only=read_only, sasl_server_principal=sasl_server_principal)
  
    zk.start()
  
    children_data = []
  
    children = zk.get_children(namespace)
  
    for node in children:
      data, stat = zk.get("%s/%s" % (namespace, node))
      children_data.append(data)
  
    zk.stop()
-   
+ 
    return children_data
  
Enable Kerberos automatically based on HDFS security
## Code Before:

from kazoo.client import KazooClient
from libzookeeper.conf import PRINCIPAL_NAME


def get_children_data(ensemble, namespace, read_only=True):
  zk = KazooClient(hosts=ensemble, read_only=read_only, sasl_server_principal=PRINCIPAL_NAME.get())

  zk.start()

  children_data = []

  children = zk.get_children(namespace)

  for node in children:
    data, stat = zk.get("%s/%s" % (namespace, node))
    children_data.append(data)

  zk.stop()
  
  return children_data

## Instruction:
Enable Kerberos automatically based on HDFS security
## Code After:

from kazoo.client import KazooClient

from hadoop import cluster
from desktop.lib.exceptions_renderable import PopupException

from libzookeeper.conf import PRINCIPAL_NAME


def get_children_data(ensemble, namespace, read_only=True):
  hdfs = cluster.get_hdfs()
  if hdfs is None:
    raise PopupException(_('No [hdfs] configured in hue.ini.'))

  if hdfs.security_enabled:
    sasl_server_principal = PRINCIPAL_NAME.get()
  else:
    sasl_server_principal = None

  zk = KazooClient(hosts=ensemble, read_only=read_only, sasl_server_principal=sasl_server_principal)

  zk.start()

  children_data = []

  children = zk.get_children(namespace)

  for node in children:
    data, stat = zk.get("%s/%s" % (namespace, node))
    children_data.append(data)

  zk.stop()

  return children_data
