PKG-INFO 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. Metadata-Version: 2.1
  2. Name: apache-ranger
  3. Version: 0.0.3
  4. Summary: Apache Ranger Python client
  5. Home-page: https://github.com/apache/ranger/tree/master/intg/src/main/python
  6. Author: Apache Ranger
  7. Author-email: dev@ranger.apache.org
  8. License: Apache LICENSE 2.0
  9. Description: <!---
  10. Licensed to the Apache Software Foundation (ASF) under one
  11. or more contributor license agreements. See the NOTICE file
  12. distributed with this work for additional information
  13. regarding copyright ownership. The ASF licenses this file
  14. to you under the Apache License, Version 2.0 (the
  15. "License"); you may not use this file except in compliance
  16. with the License. You may obtain a copy of the License at
  17. http://www.apache.org/licenses/LICENSE-2.0
  18. Unless required by applicable law or agreed to in writing,
  19. software distributed under the License is distributed on an
  20. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21. KIND, either express or implied. See the License for the
  22. specific language governing permissions and limitations
  23. under the License.
  24. -->
  25. # Apache Ranger - Python client
  26. Python library for Apache Ranger.
  27. ## Installation
  28. Use the package manager [pip](https://pip.pypa.io/en/stable/) to install python client for Apache Ranger.
  29. ```bash
  30. > pip install apache-ranger
  31. ```
  32. Verify if apache-ranger client is installed:
  33. ```bash
  34. > pip list
  35. Package Version
  36. ------------ ---------
  37. apache-ranger 0.0.3
  38. ```
  39. ## Usage
  40. ```python test_ranger.py```
  41. ```python
  42. # test_ranger.py
  43. from apache_ranger.model.ranger_service import *
  44. from apache_ranger.client.ranger_client import *
  45. from apache_ranger.model.ranger_policy import *
  46. ## Step 1: create a client to connect to Apache Ranger admin
  47. ranger_url = 'http://localhost:6080'
  48. ranger_auth = ('admin', 'rangerR0cks!')
  49. # For Kerberos authentication
  50. #
  51. # from requests_kerberos import HTTPKerberosAuth
  52. #
  53. # ranger_auth = HTTPKerberosAuth()
  54. ranger = RangerClient(ranger_url, ranger_auth)
  55. # to disable SSL certificate validation (not recommended for production use!)
  56. #
  57. # ranger.session.verify = False
  58. ## Step 2: Let's create a service
  59. service = RangerService()
  60. service.name = 'test_hive'
  61. service.type = 'hive'
  62. service.configs = {'username':'hive', 'password':'hive', 'jdbc.driverClassName': 'org.apache.hive.jdbc.HiveDriver', 'jdbc.url': 'jdbc:hive2://ranger-hadoop:10000', 'hadoop.security.authorization': 'true'}
  63. print('Creating service: name=' + service.name)
  64. created_service = ranger.create_service(service)
  65. print(' created service: name=' + created_service.name + ', id=' + str(created_service.id))
  66. ## Step 3: Let's create a policy
  67. policy = RangerPolicy()
  68. policy.service = service.name
  69. policy.name = 'test policy'
  70. policy.resources = { 'database': RangerPolicyResource({ 'values': ['test_db'] }),
  71. 'table': RangerPolicyResource({ 'values': ['test_tbl'] }),
  72. 'column': RangerPolicyResource({ 'values': ['*'] }) }
  73. allowItem1 = RangerPolicyItem()
  74. allowItem1.users = [ 'admin' ]
  75. allowItem1.accesses = [ RangerPolicyItemAccess({ 'type': 'create' }),
  76. RangerPolicyItemAccess({ 'type': 'alter' }) ]
  77. denyItem1 = RangerPolicyItem()
  78. denyItem1.users = [ 'admin' ]
  79. denyItem1.accesses = [ RangerPolicyItemAccess({ 'type': 'drop' }) ]
  80. policy.policyItems = [ allowItem1 ]
  81. policy.denyPolicyItems = [ denyItem1 ]
  82. print('Creating policy: name=' + policy.name)
  83. created_policy = ranger.create_policy(policy)
  84. print(' created policy: name=' + created_policy.name + ', id=' + str(created_policy.id))
  85. ## Step 4: Delete policy and service created above
  86. print('Deleting policy: id=' + str(created_policy.id))
  87. ranger.delete_policy_by_id(created_policy.id)
  88. print(' deleted policy: id=' + str(created_policy.id))
  89. print('Deleting service: id=' + str(created_service.id))
  90. ranger.delete_service_by_id(created_service.id)
  91. print(' deleted service: id=' + str(created_service.id))
  92. ```
  93. For more examples, checkout `sample-client` python project in [ranger-examples](https://github.com/apache/ranger/blob/master/ranger-examples/sample-client/src/main/python/sample_client.py) module.
  94. Keywords: ranger client,apache ranger
  95. Platform: UNKNOWN
  96. Classifier: Programming Language :: Python :: 2.7
  97. Classifier: License :: OSI Approved :: Apache Software License
  98. Classifier: Operating System :: OS Independent
  99. Requires-Python: >=2.7
  100. Description-Content-Type: text/markdown