You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ma...@apache.org on 2020/08/17 20:27:53 UTC
[ranger] branch ranger-2.1 updated: RANGER-2927: added packaging
for Python client
This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch ranger-2.1
in repository https://gitbox.apache.org/repos/asf/ranger.git
The following commit(s) were added to refs/heads/ranger-2.1 by this push:
new a74bbb7 RANGER-2927: added packaging for Python client
a74bbb7 is described below
commit a74bbb71252ec472b7939ec6c7a2745aac6b543f
Author: Madhan Neethiraj <ma...@apache.org>
AuthorDate: Fri Aug 14 22:06:21 2020 -0700
RANGER-2927: added packaging for Python client
(cherry picked from commit 758ef30008d4f4da430417f8d69285679444a562)
---
intg/src/main/python/LICENSE | 201 +++++++++++++++++++++
intg/src/main/python/README.md | 2 +
.../{ranger/model => apache_ranger}/__init__.py | 0
.../{ranger => apache_ranger}/client/__init__.py | 0
.../client/ranger_client.py | 45 ++---
.../python/{ => apache_ranger/model}/__init__.py | 0
.../model/grant_revoke_role_request.py | 0
.../{ranger => apache_ranger}/model/ranger_base.py | 0
.../model/ranger_policy.py | 2 +-
.../{ranger => apache_ranger}/model/ranger_role.py | 2 +-
.../model/ranger_security_zone.py | 2 +-
.../model/ranger_service.py | 2 +-
.../model/ranger_service_def.py | 2 +-
intg/src/main/python/setup.py | 22 +++
.../sample-client/scripts/run-pyclient.sh | 0
.../sample-client/scripts/run-sample-client.sh | 0
.../sample-client/src/main/python/sample_client.py | 64 +++++--
.../sample-client}/src/main/resources/logging.conf | 0
18 files changed, 300 insertions(+), 44 deletions(-)
diff --git a/intg/src/main/python/LICENSE b/intg/src/main/python/LICENSE
new file mode 100644
index 0000000..78b7111
--- /dev/null
+++ b/intg/src/main/python/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
diff --git a/intg/src/main/python/README.md b/intg/src/main/python/README.md
new file mode 100644
index 0000000..8d35190
--- /dev/null
+++ b/intg/src/main/python/README.md
@@ -0,0 +1,2 @@
+# Apache Ranger - Python client
+
diff --git a/intg/src/main/python/ranger/model/__init__.py b/intg/src/main/python/apache_ranger/__init__.py
similarity index 100%
rename from intg/src/main/python/ranger/model/__init__.py
rename to intg/src/main/python/apache_ranger/__init__.py
diff --git a/intg/src/main/python/ranger/client/__init__.py b/intg/src/main/python/apache_ranger/client/__init__.py
similarity index 100%
rename from intg/src/main/python/ranger/client/__init__.py
rename to intg/src/main/python/apache_ranger/client/__init__.py
diff --git a/intg/src/main/python/ranger/client/ranger_client.py b/intg/src/main/python/apache_ranger/client/ranger_client.py
similarity index 92%
rename from intg/src/main/python/ranger/client/ranger_client.py
rename to intg/src/main/python/apache_ranger/client/ranger_client.py
index 319261d..c95d0d9 100644
--- a/intg/src/main/python/ranger/client/ranger_client.py
+++ b/intg/src/main/python/apache_ranger/client/ranger_client.py
@@ -21,25 +21,22 @@ import enum
import json
import logging
import requests
-import logging.config
-from os import path
from http import HTTPStatus
from requests import Session, Response
-from ranger.model.ranger_role import RangerRole
-from ranger.model.ranger_policy import RangerPolicy
-from ranger.model.ranger_service import RangerService
-from ranger.model.ranger_service_def import RangerServiceDef
-from ranger.model.ranger_security_zone import RangerSecurityZone
+from apache_ranger.model.ranger_role import RangerRole
+from apache_ranger.model.ranger_policy import RangerPolicy
+from apache_ranger.model.ranger_service import RangerService
+from apache_ranger.model.ranger_service_def import RangerServiceDef
+from apache_ranger.model.ranger_security_zone import RangerSecurityZone
APPLICATION_JSON = 'application/json'
-LOG_CONFIG = path.dirname(__file__) + '/../../../resources/logging.conf'
-logging.config.fileConfig(LOG_CONFIG, disable_existing_loggers=False)
requests.packages.urllib3.disable_warnings()
+log = logging.getLogger(__name__)
class Message:
def __init__(self, name=None, rbKey=None, message=None, objectId=None, fieldName=None):
@@ -73,7 +70,6 @@ class HttpMethod(enum.Enum):
class API:
def __init__(self, path, method, expected_status, consumes=APPLICATION_JSON, produces=APPLICATION_JSON):
- self.log = logging.getLogger(__name__)
self.path = path
self.method = method
self.expected_status = expected_status
@@ -84,15 +80,15 @@ class API:
session.headers['Accept'] = self.consumes
session.headers['Content-type'] = self.produces
- if self.log.isEnabledFor(logging.DEBUG):
- self.log.debug('==> call({},{},{})'.format(self, params, request))
- self.log.debug('------------------------------------------------------')
- self.log.debug('Call : {} {}'.format(self.method, self.path))
- self.log.debug('Content-type : {}'.format(self.consumes))
- self.log.debug('Accept : {}'.format(self.produces))
+ if log.isEnabledFor(logging.DEBUG):
+ log.debug('==> call({},{},{})'.format(self, params, request))
+ log.debug('------------------------------------------------------')
+ log.debug('Call : {} {}'.format(self.method, self.path))
+ log.debug('Content-type : {}'.format(self.consumes))
+ log.debug('Accept : {}'.format(self.produces))
if request is not None:
- self.log.debug("Request : {}".format(request))
+ log.debug("Request : {}".format(request))
path = baseUrl + self.path
@@ -109,21 +105,21 @@ class API:
if client_response.status_code == self.expected_status:
if client_response.content:
- if self.log.isEnabledFor(logging.DEBUG):
- self.log.debug('Response: {}'.format(client_response.text))
+ if log.isEnabledFor(logging.DEBUG):
+ log.debug('Response: {}'.format(client_response.text))
else:
return None
elif client_response.status_code == HTTPStatus.SERVICE_UNAVAILABLE:
- self.log.error('Ranger Admin unavailable. HTTP Status: {}'.format(HTTPStatus.SERVICE_UNAVAILABLE))
- self.log.error("client_response=: {}" + str(client_response))
+ log.error('Ranger Admin unavailable. HTTP Status: {}'.format(HTTPStatus.SERVICE_UNAVAILABLE))
+ log.error("client_response=: {}" + str(client_response))
return None
else:
raise Exception(client_response.text)
__json = json.loads(str(json.dumps(client_response.json())))
- if self.log.isEnabledFor(logging.DEBUG):
- self.log.debug('<== call({},{},{}), result = {}'.format(self, params, request, client_response))
+ if log.isEnabledFor(logging.DEBUG):
+ log.debug('<== call({},{},{}), result = {}'.format(self, params, request, client_response))
return __json
@@ -131,7 +127,7 @@ class API:
try:
return API(self.path.format(**params), self.method, self.expected_status, self.consumes, self.produces)
except (KeyError, TypeError) as e:
- self.log.error('Arguments not formatted properly' + str(e))
+ log.error('Arguments not formatted properly' + str(e))
raise e
@@ -232,7 +228,6 @@ class RangerClient:
DELETE_POLICY_DELTAS = API(URI_POLICY_DELTAS, HttpMethod.DELETE, HTTPStatus.NO_CONTENT)
def __init__(self, url, username, password):
- self.log = logging.getLogger(__name__)
self.__password = password
self.url = url
self.username = username
diff --git a/intg/src/main/python/__init__.py b/intg/src/main/python/apache_ranger/model/__init__.py
similarity index 100%
rename from intg/src/main/python/__init__.py
rename to intg/src/main/python/apache_ranger/model/__init__.py
diff --git a/intg/src/main/python/ranger/model/grant_revoke_role_request.py b/intg/src/main/python/apache_ranger/model/grant_revoke_role_request.py
similarity index 100%
rename from intg/src/main/python/ranger/model/grant_revoke_role_request.py
rename to intg/src/main/python/apache_ranger/model/grant_revoke_role_request.py
diff --git a/intg/src/main/python/ranger/model/ranger_base.py b/intg/src/main/python/apache_ranger/model/ranger_base.py
similarity index 100%
rename from intg/src/main/python/ranger/model/ranger_base.py
rename to intg/src/main/python/apache_ranger/model/ranger_base.py
diff --git a/intg/src/main/python/ranger/model/ranger_policy.py b/intg/src/main/python/apache_ranger/model/ranger_policy.py
similarity index 99%
rename from intg/src/main/python/ranger/model/ranger_policy.py
rename to intg/src/main/python/apache_ranger/model/ranger_policy.py
index 9195f4b..2136989 100644
--- a/intg/src/main/python/ranger/model/ranger_policy.py
+++ b/intg/src/main/python/apache_ranger/model/ranger_policy.py
@@ -18,7 +18,7 @@
import json
-from ranger.model.ranger_base import RangerBase
+from apache_ranger.model.ranger_base import RangerBase
class RangerPolicyResource:
diff --git a/intg/src/main/python/ranger/model/ranger_role.py b/intg/src/main/python/apache_ranger/model/ranger_role.py
similarity index 97%
rename from intg/src/main/python/ranger/model/ranger_role.py
rename to intg/src/main/python/apache_ranger/model/ranger_role.py
index aa05216..1c698ed 100644
--- a/intg/src/main/python/ranger/model/ranger_role.py
+++ b/intg/src/main/python/apache_ranger/model/ranger_role.py
@@ -18,7 +18,7 @@
import json
-from ranger.model.ranger_base import RangerBase
+from apache_ranger.model.ranger_base import RangerBase
class RoleMember:
diff --git a/intg/src/main/python/ranger/model/ranger_security_zone.py b/intg/src/main/python/apache_ranger/model/ranger_security_zone.py
similarity index 97%
rename from intg/src/main/python/ranger/model/ranger_security_zone.py
rename to intg/src/main/python/apache_ranger/model/ranger_security_zone.py
index 40a5209..9ed8208 100644
--- a/intg/src/main/python/ranger/model/ranger_security_zone.py
+++ b/intg/src/main/python/apache_ranger/model/ranger_security_zone.py
@@ -18,7 +18,7 @@
import json
-from ranger.model.ranger_base import RangerBase
+from apache_ranger.model.ranger_base import RangerBase
class RangerSecurityZoneService:
diff --git a/intg/src/main/python/ranger/model/ranger_service.py b/intg/src/main/python/apache_ranger/model/ranger_service.py
similarity index 97%
rename from intg/src/main/python/ranger/model/ranger_service.py
rename to intg/src/main/python/apache_ranger/model/ranger_service.py
index 637c38f..e07a706 100644
--- a/intg/src/main/python/ranger/model/ranger_service.py
+++ b/intg/src/main/python/apache_ranger/model/ranger_service.py
@@ -18,7 +18,7 @@
import json
-from ranger.model.ranger_base import RangerBase
+from apache_ranger.model.ranger_base import RangerBase
class RangerService(RangerBase):
diff --git a/intg/src/main/python/ranger/model/ranger_service_def.py b/intg/src/main/python/apache_ranger/model/ranger_service_def.py
similarity index 99%
rename from intg/src/main/python/ranger/model/ranger_service_def.py
rename to intg/src/main/python/apache_ranger/model/ranger_service_def.py
index 8cd4757..ec3845d 100644
--- a/intg/src/main/python/ranger/model/ranger_service_def.py
+++ b/intg/src/main/python/apache_ranger/model/ranger_service_def.py
@@ -18,7 +18,7 @@
import json
-from ranger.model.ranger_base import RangerBase
+from apache_ranger.model.ranger_base import RangerBase
class RangerDataMaskDef:
diff --git a/intg/src/main/python/setup.py b/intg/src/main/python/setup.py
new file mode 100644
index 0000000..93277ec
--- /dev/null
+++ b/intg/src/main/python/setup.py
@@ -0,0 +1,22 @@
+import setuptools
+
+with open("README.md", "r") as fh:
+ long_description = fh.read()
+
+setuptools.setup(
+ name="apache-ranger",
+ version="0.0.1",
+ author="Apache Ranger",
+ author_email="dev@ranger.apache.org",
+ description="Apache Ranger Python client",
+ long_description=long_description,
+ long_description_content_type="text/markdown",
+ url="https://github.com/apache/ranger/tree/master/intg/src/main/python",
+ packages=setuptools.find_packages(),
+ classifiers=[
+ "Programming Language :: Python :: 3",
+ "License :: OSI Approved :: Apache Software License",
+ "Operating System :: OS Independent",
+ ],
+ python_requires='>=3.6',
+)
diff --git a/ranger-examples/sample-client/scripts/run-pyclient.sh b/ranger-examples/sample-client/scripts/run-pyclient.sh
old mode 100644
new mode 100755
diff --git a/ranger-examples/sample-client/scripts/run-sample-client.sh b/ranger-examples/sample-client/scripts/run-sample-client.sh
old mode 100644
new mode 100755
diff --git a/ranger-examples/sample-client/src/main/python/sample_client.py b/ranger-examples/sample-client/src/main/python/sample_client.py
index 7ff6e70..1d1c331 100644
--- a/ranger-examples/sample-client/src/main/python/sample_client.py
+++ b/ranger-examples/sample-client/src/main/python/sample_client.py
@@ -19,92 +19,128 @@
import argparse
import logging.config
-from ranger.model.ranger_service import RangerService
-from ranger.model.ranger_role import RangerRole, RoleMember
-from ranger.client.ranger_client import RangerClient, LOG_CONFIG
-from ranger.model.ranger_policy import RangerPolicy, RangerPolicyResource
-from ranger.model.ranger_service_def import RangerServiceConfigDef, RangerAccessTypeDef, RangerResourceDef, RangerServiceDef
+from os import path
+
+from apache_ranger.model.ranger_service import RangerService
+from apache_ranger.model.ranger_role import RangerRole, RoleMember
+from apache_ranger.client.ranger_client import RangerClient
+from apache_ranger.model.ranger_policy import RangerPolicy, RangerPolicyResource
+from apache_ranger.model.ranger_service_def import RangerServiceConfigDef, RangerAccessTypeDef, RangerResourceDef, RangerServiceDef
+
+LOG_CONFIG = path.dirname(__file__) + '/../resources/logging.conf'
logging.config.fileConfig(LOG_CONFIG, disable_existing_loggers=False)
+
log = logging.getLogger(__name__)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Parameters required for connection to Ranger Admin!')
+
parser.add_argument('--url', default='http://localhost:6080')
parser.add_argument('--username')
parser.add_argument('--password')
+
args = parser.parse_args()
service_def_name = "sampleServiceDef"
- service_name = "sampleService"
- policy_name = "samplePolicy"
- role_name = "sampleRole"
+ service_name = "sampleService"
+ policy_name = "samplePolicy"
+ role_name = "sampleRole"
ranger_client = RangerClient(args.url, args.username, args.password)
+
# create a new service definition
- config = RangerServiceConfigDef(itemId=1, name='sampleConfig', type='string')
- access_type = RangerAccessTypeDef(itemId=1, name='sampleAccess')
+ config = RangerServiceConfigDef(itemId=1, name='sampleConfig', type='string')
+ access_type = RangerAccessTypeDef(itemId=1, name='sampleAccess')
resource_def = RangerResourceDef(itemId=1, name='root', type='string')
- service_def = RangerServiceDef(name=service_def_name, configs=[config], accessTypes=[access_type],
- resources=[resource_def])
+ service_def = RangerServiceDef(name=service_def_name, configs=[config], accessTypes=[access_type],
+ resources=[resource_def])
created_service_def = ranger_client.create_service_def(service_def)
+
log.info('New Service Definition created successfully {}'.format(created_service_def))
+
# create a new service
service = RangerService(name=service_name, type=service_def_name)
created_service = ranger_client.create_service(service)
+
log.info('New Service created successfully {}'.format(created_service))
+
# create a new policy
resource = RangerPolicyResource(['/path/to/sample/resource'], False, False)
- policy = RangerPolicy(service=service_name, name=policy_name, resources={'root': resource})
+ policy = RangerPolicy(service=service_name, name=policy_name, resources={'root': resource})
+
created_policy = ranger_client.create_policy(policy)
+
log.info('New Ranger Policy created successfully {}'.format(created_policy))
+
# update an existing policy
policy = RangerPolicy(service=service_name, name=policy_name, description='Policy Updated!')
+
updated_policy = ranger_client.update_policy(service_name, policy_name, policy)
+
log.info('Ranger Policy updated successfully {}'.format(updated_policy))
+
# get a policy by name
fetched_policy = ranger_client.get_policy(service_name, policy_name)
+
log.info('Policy {} fetched {}'.format(policy_name, fetched_policy))
+
# get all policies
all_policies = ranger_client.find_policies({})
+
for id, policy in enumerate(all_policies):
log.info('Policy #{}: {}'.format(id, RangerPolicy(**policy)))
+
# delete a policy by name
ranger_client.delete_policy(service_name, policy_name)
+
log.info('Policy {} successfully deleted'.format(policy_name))
+
# create a role in ranger
sample_role = RangerRole(name=role_name, description='Sample Role', users=[RoleMember(isAdmin=True)])
+
created_role = ranger_client.create_role(service_name, sample_role)
+
log.info('New Role successfully created {}'.format(created_role))
+
# update a role in ranger
sample_role = RangerRole(name=role_name, description='Updated Sample Role!')
+
updated_role = ranger_client.update_role(created_role.id, sample_role)
+
log.info('Role {} successfully updated {}'.format(role_name, updated_role))
+
# get all roles in ranger
all_roles = ranger_client.find_roles({})
+
log.info('List of Roles {}'.format(all_roles)) if all_roles is not None else log.info('No roles found!')
+
# delete a role in ranger
ranger_client.delete_role(role_name, ranger_client.username, service_name)
+
log.info('Role {} successfully deleted'.format(role_name))
+
# delete a service
ranger_client.delete_service(service_name)
+
log.info('Service {} successfully deleted'.format(service_name))
+
# delete a service definition
ranger_client.delete_service_def(service_def_name)
- log.info('Service Definition {} successfully deleted'.format(service_def_name))
+ log.info('Service Definition {} successfully deleted'.format(service_def_name))
diff --git a/intg/src/main/resources/logging.conf b/ranger-examples/sample-client/src/main/resources/logging.conf
similarity index 100%
rename from intg/src/main/resources/logging.conf
rename to ranger-examples/sample-client/src/main/resources/logging.conf