Python client for Apache Ranger 2.3.0
Project description
Apache Ranger - Python client
Python client for Apache Ranger 2.3.0.
Installation
Use the package manager pip to install python client for Apache Ranger.
> pip install apache-ranger
Verify if apache-ranger client is installed:
> pip list
Package Version
------------ ---------
apache-ranger 0.0.6
Usage
python test_ranger.py
# test_ranger.py
from apache_ranger.model.ranger_service import *
from apache_ranger.client.ranger_client import *
from apache_ranger.model.ranger_policy import *
## Step 1: create a client to connect to Apache Ranger admin
ranger_url = 'http://localhost:6080'
ranger_auth = ('admin', 'rangerR0cks!')
# For Kerberos authentication
#
# from requests_kerberos import HTTPKerberosAuth
#
# ranger_auth = HTTPKerberosAuth()
ranger = RangerClient(ranger_url, ranger_auth)
# to disable SSL certificate validation (not recommended for production use!)
#
# ranger.session.verify = False
## Step 2: Let's create a service
service = RangerService()
service.name = 'test_hive'
service.type = 'hive'
service.configs = {'username':'hive', 'password':'hive', 'jdbc.driverClassName': 'org.apache.hive.jdbc.HiveDriver', 'jdbc.url': 'jdbc:hive2://ranger-hadoop:10000', 'hadoop.security.authorization': 'true'}
print('Creating service: name=' + service.name)
created_service = ranger.create_service(service)
print(' created service: name=' + created_service.name + ', id=' + str(created_service.id))
## Step 3: Let's create a policy
policy = RangerPolicy()
policy.service = service.name
policy.name = 'test policy'
policy.resources = { 'database': RangerPolicyResource({ 'values': ['test_db'] }),
'table': RangerPolicyResource({ 'values': ['test_tbl'] }),
'column': RangerPolicyResource({ 'values': ['*'] }) }
allowItem1 = RangerPolicyItem()
allowItem1.users = [ 'admin' ]
allowItem1.accesses = [ RangerPolicyItemAccess({ 'type': 'create' }),
RangerPolicyItemAccess({ 'type': 'alter' }) ]
denyItem1 = RangerPolicyItem()
denyItem1.users = [ 'admin' ]
denyItem1.accesses = [ RangerPolicyItemAccess({ 'type': 'drop' }) ]
policy.policyItems = [ allowItem1 ]
policy.denyPolicyItems = [ denyItem1 ]
print('Creating policy: name=' + policy.name)
created_policy = ranger.create_policy(policy)
print(' created policy: name=' + created_policy.name + ', id=' + str(created_policy.id))
## Step 4: Delete policy and service created above
print('Deleting policy: id=' + str(created_policy.id))
ranger.delete_policy_by_id(created_policy.id)
print(' deleted policy: id=' + str(created_policy.id))
print('Deleting service: id=' + str(created_service.id))
ranger.delete_service_by_id(created_service.id)
print(' deleted service: id=' + str(created_service.id))
For more examples, checkout sample-client
python project in ranger-examples module.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
apache-ranger-0.0.6.tar.gz
(12.4 kB
view details)
Built Distribution
File details
Details for the file apache-ranger-0.0.6.tar.gz
.
File metadata
- Download URL: apache-ranger-0.0.6.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95c9720dc18a6c6a906ae4392298d5c7bbad470b2b4dc59e3527f3e54cbcd288 |
|
MD5 | 2d64d8c6739ac2a81c53d413d55e1645 |
|
BLAKE2b-256 | 4abe383c5d691e10d5c2e9f8f2ae1ff333d27bd373478c83db98f34b6c11b8e9 |
File details
Details for the file apache_ranger-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: apache_ranger-0.0.6-py3-none-any.whl
- Upload date:
- Size: 26.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c19afe72a69f0e904f1e999492f5fbef2e9991dd52ca58f6327af8295238e31 |
|
MD5 | db1dccb11e2cd368023c162fd84b1402 |
|
BLAKE2b-256 | f1a1375fc47665674a7b593ec70f112a8ecde24db839b2b92de1ab4a841bb27e |