You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ranger.apache.org by Madhan Neethiraj <ma...@apache.org> on 2020/12/04 16:55:28 UTC
[ANNOUNCE] Apache Ranger - Python client
All,
Official Python client for Apache Ranger is now available at PyPi.org here. Python client APIs mirror Apache Ranger REST APIs, and enable administration of Apache Ranger using Python.
Here is a sample usage to create a service and a policy using Python client:
from apache_ranger.model.ranger_service import RangerService
from apache_ranger.client.ranger_client import RangerClient
from apache_ranger.model.ranger_policy import RangerPolicy, RangerPolicyResource, RangerPolicyItem, RangerPolicyItemAccess
service_name = 'dev_hive'
service = RangerService(name=service_name, type='hive')
service.configs = {'username':'hive', 'password':'hive', 'jdbc.driverClassName': 'org.apache.hive.jdbc.HiveDriver', 'jdbc.url': 'jdfb:hive2://ranger-hadoop:10000', 'hadoop.security.authorization': 'true'}
policy = RangerPolicy(service=service_name, name='test policy')
policy.resources = {'database': RangerPolicyResource(['test_db']), 'table': RangerPolicyResource(['test_tbl']), 'column': RangerPolicyResource(['*'])}
policy.policyItems.append(RangerPolicyItem(users=['admin'], accesses=[RangerPolicyItemAccess('create'), RangerPolicyItemAccess('alter'), RangerPolicyItemAccess('drop')], delegateAdmin=True))
policy.denyPolicyItems.append(RangerPolicyItem(users=['admin'], accesses=[RangerPolicyItemAccess('select')]))
ranger_client = RangerClient('http://localhost:6080', 'admin', 'rangerR0cks!')
created_service = ranger_client.create_service(service)
created_policy = ranger_client.create_policy(policy)
Apache Ranger team is updating the documentation to include details of Python APIs.
Your feedback and suggestions are welcome.
Thanks,
Madhan