Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,527 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
Metadata-Version: 2.1 | ||
Name: apache-ranger | ||
Version: 0.0.3 | ||
Summary: Apache Ranger Python client | ||
Home-page: https://github.com/apache/ranger/tree/master/intg/src/main/python | ||
Author: Apache Ranger | ||
Author-email: dev@ranger.apache.org | ||
License: Apache LICENSE 2.0 | ||
Description: <!--- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF 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. | ||
--> | ||
|
||
# Apache Ranger - Python client | ||
|
||
Python library for Apache Ranger. | ||
|
||
## Installation | ||
|
||
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install python client for Apache Ranger. | ||
|
||
```bash | ||
> pip install apache-ranger | ||
``` | ||
|
||
Verify if apache-ranger client is installed: | ||
```bash | ||
> pip list | ||
|
||
Package Version | ||
------------ --------- | ||
apache-ranger 0.0.3 | ||
``` | ||
|
||
## Usage | ||
|
||
```python test_ranger.py``` | ||
```python | ||
# 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](https://github.com/apache/ranger/blob/master/ranger-examples/sample-client/src/main/python/sample_client.py) module. | ||
|
||
Keywords: ranger client,apache ranger | ||
Platform: UNKNOWN | ||
Classifier: Programming Language :: Python :: 2.7 | ||
Classifier: License :: OSI Approved :: Apache Software License | ||
Classifier: Operating System :: OS Independent | ||
Requires-Python: >=2.7 | ||
Description-Content-Type: text/markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<!--- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF 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. | ||
--> | ||
|
||
# Apache Ranger - Python client | ||
|
||
Python library for Apache Ranger. | ||
|
||
## Installation | ||
|
||
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install python client for Apache Ranger. | ||
|
||
```bash | ||
> pip install apache-ranger | ||
``` | ||
|
||
Verify if apache-ranger client is installed: | ||
```bash | ||
> pip list | ||
|
||
Package Version | ||
------------ --------- | ||
apache-ranger 0.0.3 | ||
``` | ||
|
||
## Usage | ||
|
||
```python test_ranger.py``` | ||
```python | ||
# 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](https://github.com/apache/ranger/blob/master/ranger-examples/sample-client/src/main/python/sample_client.py) module. |
17 changes: 17 additions & 0 deletions
17
desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env python | ||
|
||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF 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. |
17 changes: 17 additions & 0 deletions
17
desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/client/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env python | ||
|
||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF 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. |
Oops, something went wrong.