#!/usr/bin/env python
# Licensed to Cloudera, Inc. under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  Cloudera, Inc. licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from libsentry.client import SentryClient
from libsentry.conf import HOSTNAME, PORT

import logging


LOG = logging.getLogger(__name__)


class SentryException(Exception):
  def __init__(self, e):
    super(SentryException, self).__init__(e)
    self.message = e.status.message

  def __str__(self):
    return self.message


def get_api(user):
  return SentryApi(SentryClient(HOSTNAME.get(), PORT.get(), user.username))


class SentryApi(object):

  def __init__(self, client):
    self.client = client


  def create_sentry_role(self, roleName):
    response = self.client.create_sentry_role(roleName)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def drop_sentry_role(self, roleName):
    response = self.client.drop_sentry_role(roleName)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def alter_sentry_role_grant_privilege(self, roleName, tSentryPrivilege):
    response = self.client.alter_sentry_role_grant_privilege(roleName, tSentryPrivilege)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def alter_sentry_role_revoke_privilege(self, roleName, tSentryPrivilege):
    response = self.client.alter_sentry_role_revoke_privilege(roleName, tSentryPrivilege)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def alter_sentry_role_add_groups(self, roleName, groups):
    response = self.client.alter_sentry_role_add_groups(roleName, groups)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def alter_sentry_role_delete_groups(self, roleName, groups):
    response = self.client.alter_sentry_role_delete_groups(roleName, groups)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def list_sentry_roles_by_group(self, groupName=None):
    response = self.client.list_sentry_roles_by_group(groupName)

    if response.status.value == 0:
      roles = []
      for role in response.roles:
        roles.append({
          'name': role.roleName,
          'groups': [group.groupName for group in role.groups]
        })
      return roles
    else:
      raise SentryException(response)


  def list_sentry_privileges_by_role(self, roleName, authorizableHierarchy=None):
    response = self.client.list_sentry_privileges_by_role(roleName, authorizableHierarchy)

    if response.status.value == 0:
      return [self._massage_priviledge(privilege) for privilege in response.privileges]
    else:
      raise SentryException(response)


  def list_sentry_privileges_for_provider(self, groups, roleSet=None, authorizableHierarchy=None):
    response = self.client.list_sentry_privileges_for_provider(groups, roleSet, authorizableHierarchy)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def list_sentry_privileges_by_authorizable(self, authorizableSet, groups=None, roleSet=None):
    response = self.client.list_sentry_privileges_by_authorizable(authorizableSet, groups, roleSet)

    _privileges = []

    for authorizable, roles in response.privilegesMapByAuth.iteritems():
      _roles = {}
      for role, privileges in roles.privilegeMap.iteritems():
        _roles[role] = [self._massage_priviledge(privilege) for privilege in privileges]
      _privileges.append((self._massage_authorizable(authorizable), _roles))

    if response.status.value == 0:
      return _privileges
    else:
      raise SentryException(response)


  def drop_sentry_privileges(self, authorizableHierarchy):
    response = self.client.drop_sentry_privilege(authorizableHierarchy)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def rename_sentry_privileges(self, oldAuthorizable, newAuthorizable):
    response = self.client.rename_sentry_privilege(oldAuthorizable, newAuthorizable)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def _massage_priviledge(self, privilege):
    return {
        'scope': privilege.privilegeScope,
        'server': privilege.serverName,
        'database': privilege.dbName,
        'table': privilege.tableName,
        'URI': privilege.URI,
        'action': 'ALL' if privilege.action == '*' else privilege.action.upper(),
        'timestamp': privilege.createTime,
        'grantOption': privilege.grantOption == 1,
    }


  def _massage_authorizable(self, authorizable):
    return {
        'server': authorizable.server,
        'database': authorizable.db,
        'table': authorizable.table,
        'URI': authorizable.uri,
    }

b6d7654052b94d3282fb19872e575b7c104ceb7f
<mask token>


class SentryException(Exception):
    <mask token>
    <mask token>


<mask token>


class SentryApi(object):

    def __init__(self, client):
        self.client = client

    def create_sentry_role(self, roleName):
        response = self.client.create_sentry_role(roleName)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def drop_sentry_role(self, roleName):
        response = self.client.drop_sentry_role(roleName)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_grant_privilege(self, roleName, tSentryPrivilege):
        response = self.client.alter_sentry_role_grant_privilege(roleName,
            tSentryPrivilege)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_revoke_privilege(self, roleName, tSentryPrivilege):
        response = self.client.alter_sentry_role_revoke_privilege(roleName,
            tSentryPrivilege)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_add_groups(self, roleName, groups):
        response = self.client.alter_sentry_role_add_groups(roleName, groups)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_delete_groups(self, roleName, groups):
        response = self.client.alter_sentry_role_delete_groups(roleName, groups
            )
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def list_sentry_roles_by_group(self, groupName=None):
        response = self.client.list_sentry_roles_by_group(groupName)
        if response.status.value == 0:
            roles = []
            for role in response.roles:
                roles.append({'name': role.roleName, 'groups': [group.
                    groupName for group in role.groups]})
            return roles
        else:
            raise SentryException(response)

    def list_sentry_privileges_by_role(self, roleName,
        authorizableHierarchy=None):
        response = self.client.list_sentry_privileges_by_role(roleName,
            authorizableHierarchy)
        if response.status.value == 0:
            return [self._massage_priviledge(privilege) for privilege in
                response.privileges]
        else:
            raise SentryException(response)

    def list_sentry_privileges_for_provider(self, groups, roleSet=None,
        authorizableHierarchy=None):
        response = self.client.list_sentry_privileges_for_provider(groups,
            roleSet, authorizableHierarchy)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def list_sentry_privileges_by_authorizable(self, authorizableSet,
        groups=None, roleSet=None):
        response = self.client.list_sentry_privileges_by_authorizable(
            authorizableSet, groups, roleSet)
        _privileges = []
        for authorizable, roles in response.privilegesMapByAuth.iteritems():
            _roles = {}
            for role, privileges in roles.privilegeMap.iteritems():
                _roles[role] = [self._massage_priviledge(privilege) for
                    privilege in privileges]
            _privileges.append((self._massage_authorizable(authorizable),
                _roles))
        if response.status.value == 0:
            return _privileges
        else:
            raise SentryException(response)

    def drop_sentry_privileges(self, authorizableHierarchy):
        response = self.client.drop_sentry_privilege(authorizableHierarchy)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def rename_sentry_privileges(self, oldAuthorizable, newAuthorizable):
        response = self.client.rename_sentry_privilege(oldAuthorizable,
            newAuthorizable)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def _massage_priviledge(self, privilege):
        return {'scope': privilege.privilegeScope, 'server': privilege.
            serverName, 'database': privilege.dbName, 'table': privilege.
            tableName, 'URI': privilege.URI, 'action': 'ALL' if privilege.
            action == '*' else privilege.action.upper(), 'timestamp':
            privilege.createTime, 'grantOption': privilege.grantOption == 1}

    def _massage_authorizable(self, authorizable):
        return {'server': authorizable.server, 'database': authorizable.db,
            'table': authorizable.table, 'URI': authorizable.uri}

<mask token>


class SentryException(Exception):
    <mask token>

    def __str__(self):
        return self.message


<mask token>


class SentryApi(object):

    def __init__(self, client):
        self.client = client

    def create_sentry_role(self, roleName):
        response = self.client.create_sentry_role(roleName)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def drop_sentry_role(self, roleName):
        response = self.client.drop_sentry_role(roleName)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_grant_privilege(self, roleName, tSentryPrivilege):
        response = self.client.alter_sentry_role_grant_privilege(roleName,
            tSentryPrivilege)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_revoke_privilege(self, roleName, tSentryPrivilege):
        response = self.client.alter_sentry_role_revoke_privilege(roleName,
            tSentryPrivilege)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_add_groups(self, roleName, groups):
        response = self.client.alter_sentry_role_add_groups(roleName, groups)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_delete_groups(self, roleName, groups):
        response = self.client.alter_sentry_role_delete_groups(roleName, groups
            )
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def list_sentry_roles_by_group(self, groupName=None):
        response = self.client.list_sentry_roles_by_group(groupName)
        if response.status.value == 0:
            roles = []
            for role in response.roles:
                roles.append({'name': role.roleName, 'groups': [group.
                    groupName for group in role.groups]})
            return roles
        else:
            raise SentryException(response)

    def list_sentry_privileges_by_role(self, roleName,
        authorizableHierarchy=None):
        response = self.client.list_sentry_privileges_by_role(roleName,
            authorizableHierarchy)
        if response.status.value == 0:
            return [self._massage_priviledge(privilege) for privilege in
                response.privileges]
        else:
            raise SentryException(response)

    def list_sentry_privileges_for_provider(self, groups, roleSet=None,
        authorizableHierarchy=None):
        response = self.client.list_sentry_privileges_for_provider(groups,
            roleSet, authorizableHierarchy)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def list_sentry_privileges_by_authorizable(self, authorizableSet,
        groups=None, roleSet=None):
        response = self.client.list_sentry_privileges_by_authorizable(
            authorizableSet, groups, roleSet)
        _privileges = []
        for authorizable, roles in response.privilegesMapByAuth.iteritems():
            _roles = {}
            for role, privileges in roles.privilegeMap.iteritems():
                _roles[role] = [self._massage_priviledge(privilege) for
                    privilege in privileges]
            _privileges.append((self._massage_authorizable(authorizable),
                _roles))
        if response.status.value == 0:
            return _privileges
        else:
            raise SentryException(response)

    def drop_sentry_privileges(self, authorizableHierarchy):
        response = self.client.drop_sentry_privilege(authorizableHierarchy)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def rename_sentry_privileges(self, oldAuthorizable, newAuthorizable):
        response = self.client.rename_sentry_privilege(oldAuthorizable,
            newAuthorizable)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def _massage_priviledge(self, privilege):
        return {'scope': privilege.privilegeScope, 'server': privilege.
            serverName, 'database': privilege.dbName, 'table': privilege.
            tableName, 'URI': privilege.URI, 'action': 'ALL' if privilege.
            action == '*' else privilege.action.upper(), 'timestamp':
            privilege.createTime, 'grantOption': privilege.grantOption == 1}

    def _massage_authorizable(self, authorizable):
        return {'server': authorizable.server, 'database': authorizable.db,
            'table': authorizable.table, 'URI': authorizable.uri}

<mask token>


class SentryException(Exception):

    def __init__(self, e):
        super(SentryException, self).__init__(e)
        self.message = e.status.message

    def __str__(self):
        return self.message


<mask token>


class SentryApi(object):

    def __init__(self, client):
        self.client = client

    def create_sentry_role(self, roleName):
        response = self.client.create_sentry_role(roleName)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def drop_sentry_role(self, roleName):
        response = self.client.drop_sentry_role(roleName)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_grant_privilege(self, roleName, tSentryPrivilege):
        response = self.client.alter_sentry_role_grant_privilege(roleName,
            tSentryPrivilege)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_revoke_privilege(self, roleName, tSentryPrivilege):
        response = self.client.alter_sentry_role_revoke_privilege(roleName,
            tSentryPrivilege)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_add_groups(self, roleName, groups):
        response = self.client.alter_sentry_role_add_groups(roleName, groups)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_delete_groups(self, roleName, groups):
        response = self.client.alter_sentry_role_delete_groups(roleName, groups
            )
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def list_sentry_roles_by_group(self, groupName=None):
        response = self.client.list_sentry_roles_by_group(groupName)
        if response.status.value == 0:
            roles = []
            for role in response.roles:
                roles.append({'name': role.roleName, 'groups': [group.
                    groupName for group in role.groups]})
            return roles
        else:
            raise SentryException(response)

    def list_sentry_privileges_by_role(self, roleName,
        authorizableHierarchy=None):
        response = self.client.list_sentry_privileges_by_role(roleName,
            authorizableHierarchy)
        if response.status.value == 0:
            return [self._massage_priviledge(privilege) for privilege in
                response.privileges]
        else:
            raise SentryException(response)

    def list_sentry_privileges_for_provider(self, groups, roleSet=None,
        authorizableHierarchy=None):
        response = self.client.list_sentry_privileges_for_provider(groups,
            roleSet, authorizableHierarchy)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def list_sentry_privileges_by_authorizable(self, authorizableSet,
        groups=None, roleSet=None):
        response = self.client.list_sentry_privileges_by_authorizable(
            authorizableSet, groups, roleSet)
        _privileges = []
        for authorizable, roles in response.privilegesMapByAuth.iteritems():
            _roles = {}
            for role, privileges in roles.privilegeMap.iteritems():
                _roles[role] = [self._massage_priviledge(privilege) for
                    privilege in privileges]
            _privileges.append((self._massage_authorizable(authorizable),
                _roles))
        if response.status.value == 0:
            return _privileges
        else:
            raise SentryException(response)

    def drop_sentry_privileges(self, authorizableHierarchy):
        response = self.client.drop_sentry_privilege(authorizableHierarchy)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def rename_sentry_privileges(self, oldAuthorizable, newAuthorizable):
        response = self.client.rename_sentry_privilege(oldAuthorizable,
            newAuthorizable)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def _massage_priviledge(self, privilege):
        return {'scope': privilege.privilegeScope, 'server': privilege.
            serverName, 'database': privilege.dbName, 'table': privilege.
            tableName, 'URI': privilege.URI, 'action': 'ALL' if privilege.
            action == '*' else privilege.action.upper(), 'timestamp':
            privilege.createTime, 'grantOption': privilege.grantOption == 1}

    def _massage_authorizable(self, authorizable):
        return {'server': authorizable.server, 'database': authorizable.db,
            'table': authorizable.table, 'URI': authorizable.uri}

from libsentry.client import SentryClient
from libsentry.conf import HOSTNAME, PORT
import logging
LOG = logging.getLogger(__name__)


class SentryException(Exception):

    def __init__(self, e):
        super(SentryException, self).__init__(e)
        self.message = e.status.message

    def __str__(self):
        return self.message


def get_api(user):
    return SentryApi(SentryClient(HOSTNAME.get(), PORT.get(), user.username))


class SentryApi(object):

    def __init__(self, client):
        self.client = client

    def create_sentry_role(self, roleName):
        response = self.client.create_sentry_role(roleName)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def drop_sentry_role(self, roleName):
        response = self.client.drop_sentry_role(roleName)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_grant_privilege(self, roleName, tSentryPrivilege):
        response = self.client.alter_sentry_role_grant_privilege(roleName,
            tSentryPrivilege)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_revoke_privilege(self, roleName, tSentryPrivilege):
        response = self.client.alter_sentry_role_revoke_privilege(roleName,
            tSentryPrivilege)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_add_groups(self, roleName, groups):
        response = self.client.alter_sentry_role_add_groups(roleName, groups)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def alter_sentry_role_delete_groups(self, roleName, groups):
        response = self.client.alter_sentry_role_delete_groups(roleName, groups
            )
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def list_sentry_roles_by_group(self, groupName=None):
        response = self.client.list_sentry_roles_by_group(groupName)
        if response.status.value == 0:
            roles = []
            for role in response.roles:
                roles.append({'name': role.roleName, 'groups': [group.
                    groupName for group in role.groups]})
            return roles
        else:
            raise SentryException(response)

    def list_sentry_privileges_by_role(self, roleName,
        authorizableHierarchy=None):
        response = self.client.list_sentry_privileges_by_role(roleName,
            authorizableHierarchy)
        if response.status.value == 0:
            return [self._massage_priviledge(privilege) for privilege in
                response.privileges]
        else:
            raise SentryException(response)

    def list_sentry_privileges_for_provider(self, groups, roleSet=None,
        authorizableHierarchy=None):
        response = self.client.list_sentry_privileges_for_provider(groups,
            roleSet, authorizableHierarchy)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def list_sentry_privileges_by_authorizable(self, authorizableSet,
        groups=None, roleSet=None):
        response = self.client.list_sentry_privileges_by_authorizable(
            authorizableSet, groups, roleSet)
        _privileges = []
        for authorizable, roles in response.privilegesMapByAuth.iteritems():
            _roles = {}
            for role, privileges in roles.privilegeMap.iteritems():
                _roles[role] = [self._massage_priviledge(privilege) for
                    privilege in privileges]
            _privileges.append((self._massage_authorizable(authorizable),
                _roles))
        if response.status.value == 0:
            return _privileges
        else:
            raise SentryException(response)

    def drop_sentry_privileges(self, authorizableHierarchy):
        response = self.client.drop_sentry_privilege(authorizableHierarchy)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def rename_sentry_privileges(self, oldAuthorizable, newAuthorizable):
        response = self.client.rename_sentry_privilege(oldAuthorizable,
            newAuthorizable)
        if response.status.value == 0:
            return response
        else:
            raise SentryException(response)

    def _massage_priviledge(self, privilege):
        return {'scope': privilege.privilegeScope, 'server': privilege.
            serverName, 'database': privilege.dbName, 'table': privilege.
            tableName, 'URI': privilege.URI, 'action': 'ALL' if privilege.
            action == '*' else privilege.action.upper(), 'timestamp':
            privilege.createTime, 'grantOption': privilege.grantOption == 1}

    def _massage_authorizable(self, authorizable):
        return {'server': authorizable.server, 'database': authorizable.db,
            'table': authorizable.table, 'URI': authorizable.uri}

#!/usr/bin/env python
# Licensed to Cloudera, Inc. under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  Cloudera, Inc. licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from libsentry.client import SentryClient
from libsentry.conf import HOSTNAME, PORT

import logging


LOG = logging.getLogger(__name__)


class SentryException(Exception):
  def __init__(self, e):
    super(SentryException, self).__init__(e)
    self.message = e.status.message

  def __str__(self):
    return self.message


def get_api(user):
  return SentryApi(SentryClient(HOSTNAME.get(), PORT.get(), user.username))


class SentryApi(object):

  def __init__(self, client):
    self.client = client


  def create_sentry_role(self, roleName):
    response = self.client.create_sentry_role(roleName)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def drop_sentry_role(self, roleName):
    response = self.client.drop_sentry_role(roleName)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def alter_sentry_role_grant_privilege(self, roleName, tSentryPrivilege):
    response = self.client.alter_sentry_role_grant_privilege(roleName, tSentryPrivilege)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def alter_sentry_role_revoke_privilege(self, roleName, tSentryPrivilege):
    response = self.client.alter_sentry_role_revoke_privilege(roleName, tSentryPrivilege)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def alter_sentry_role_add_groups(self, roleName, groups):
    response = self.client.alter_sentry_role_add_groups(roleName, groups)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def alter_sentry_role_delete_groups(self, roleName, groups):
    response = self.client.alter_sentry_role_delete_groups(roleName, groups)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def list_sentry_roles_by_group(self, groupName=None):
    response = self.client.list_sentry_roles_by_group(groupName)

    if response.status.value == 0:
      roles = []
      for role in response.roles:
        roles.append({
          'name': role.roleName,
          'groups': [group.groupName for group in role.groups]
        })
      return roles
    else:
      raise SentryException(response)


  def list_sentry_privileges_by_role(self, roleName, authorizableHierarchy=None):
    response = self.client.list_sentry_privileges_by_role(roleName, authorizableHierarchy)

    if response.status.value == 0:
      return [self._massage_priviledge(privilege) for privilege in response.privileges]
    else:
      raise SentryException(response)


  def list_sentry_privileges_for_provider(self, groups, roleSet=None, authorizableHierarchy=None):
    response = self.client.list_sentry_privileges_for_provider(groups, roleSet, authorizableHierarchy)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def list_sentry_privileges_by_authorizable(self, authorizableSet, groups=None, roleSet=None):
    response = self.client.list_sentry_privileges_by_authorizable(authorizableSet, groups, roleSet)

    _privileges = []

    for authorizable, roles in response.privilegesMapByAuth.iteritems():
      _roles = {}
      for role, privileges in roles.privilegeMap.iteritems():
        _roles[role] = [self._massage_priviledge(privilege) for privilege in privileges]
      _privileges.append((self._massage_authorizable(authorizable), _roles))

    if response.status.value == 0:
      return _privileges
    else:
      raise SentryException(response)


  def drop_sentry_privileges(self, authorizableHierarchy):
    response = self.client.drop_sentry_privilege(authorizableHierarchy)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def rename_sentry_privileges(self, oldAuthorizable, newAuthorizable):
    response = self.client.rename_sentry_privilege(oldAuthorizable, newAuthorizable)

    if response.status.value == 0:
      return response
    else:
      raise SentryException(response)


  def _massage_priviledge(self, privilege):
    return {
        'scope': privilege.privilegeScope,
        'server': privilege.serverName,
        'database': privilege.dbName,
        'table': privilege.tableName,
        'URI': privilege.URI,
        'action': 'ALL' if privilege.action == '*' else privilege.action.upper(),
        'timestamp': privilege.createTime,
        'grantOption': privilege.grantOption == 1,
    }


  def _massage_authorizable(self, authorizable):
    return {
        'server': authorizable.server,
        'database': authorizable.db,
        'table': authorizable.table,
        'URI': authorizable.uri,
    }
