diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/PKG-INFO b/desktop/core/ext-py/apache-ranger-0.0.3/PKG-INFO new file mode 100644 index 00000000000..73100908b1f --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/PKG-INFO @@ -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: + + # 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 diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/README.md b/desktop/core/ext-py/apache-ranger-0.0.3/README.md new file mode 100644 index 00000000000..a70fdac2b27 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/README.md @@ -0,0 +1,123 @@ + + +# 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. diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/__init__.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/__init__.py new file mode 100644 index 00000000000..ed9d0b3c4e8 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/__init__.py @@ -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. diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/client/__init__.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/client/__init__.py new file mode 100644 index 00000000000..ed9d0b3c4e8 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/client/__init__.py @@ -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. diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/client/ranger_client.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/client/ranger_client.py new file mode 100644 index 00000000000..67b21c28223 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/client/ranger_client.py @@ -0,0 +1,441 @@ +#!/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. + + +import json +import logging +import os + +from requests import Session, Response + +from apache_ranger.exceptions import RangerServiceException +from apache_ranger.model.ranger_base import RangerBase +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 +from apache_ranger.utils import * + + + +LOG = logging.getLogger(__name__) + + +class RangerClient: + def __init__(self, url, auth): + self.url = url + self.session = Session() + self.session.auth = auth + + logging.getLogger("requests").setLevel(logging.WARNING) + + + # Service Definition APIs + def create_service_def(self, serviceDef): + resp = self.__call_api(RangerClient.CREATE_SERVICEDEF, request_data=serviceDef) + + return type_coerce(resp, RangerServiceDef) + + def update_service_def_by_id(self, serviceDefId, serviceDef): + resp = self.__call_api(RangerClient.UPDATE_SERVICEDEF_BY_ID.format_path({ 'id': serviceDefId }), request_data=serviceDef) + + return type_coerce(resp, RangerServiceDef) + + def update_service_def(self, serviceDefName, serviceDef): + resp = self.__call_api(RangerClient.UPDATE_SERVICEDEF_BY_NAME.format_path({ 'name': serviceDefName }), request_data=serviceDef) + + return type_coerce(resp, RangerServiceDef) + + def delete_service_def_by_id(self, serviceDefId): + self.__call_api(RangerClient.DELETE_SERVICEDEF_BY_ID.format_path({ 'id': serviceDefId })) + + def delete_service_def(self, serviceDefName): + self.__call_api(RangerClient.DELETE_SERVICEDEF_BY_NAME.format_path({ 'name': serviceDefName })) + + def get_service_def_by_id(self, serviceDefId): + resp = self.__call_api(RangerClient.GET_SERVICEDEF_BY_ID.format_path({ 'id': serviceDefId })) + + return type_coerce(resp, RangerServiceDef) + + def get_service_def(self, serviceDefName): + resp = self.__call_api(RangerClient.GET_SERVICEDEF_BY_NAME.format_path({ 'name': serviceDefName })) + + return type_coerce(resp, RangerServiceDef) + + def find_service_defs(self, filter={}): + resp = self.__call_api(RangerClient.FIND_SERVICEDEFS, filter) + + return type_coerce_list(resp, RangerServiceDef) + + + # Service APIs + def create_service(self, service): + resp = self.__call_api(RangerClient.CREATE_SERVICE, request_data=service) + + return type_coerce(resp, RangerService) + + def get_service_by_id(self, serviceId): + resp = self.__call_api(RangerClient.GET_SERVICE_BY_ID.format_path({ 'id': serviceId })) + + return type_coerce(resp, RangerService) + + def get_service(self, serviceName): + resp = self.__call_api(RangerClient.GET_SERVICE_BY_NAME.format_path({ 'name': serviceName })) + + return type_coerce(resp, RangerService) + + def update_service_by_id(self, serviceId, service): + resp = self.__call_api(RangerClient.UPDATE_SERVICE_BY_ID.format_path({ 'id': serviceId }), request_data=service) + + return type_coerce(resp, RangerService) + + def update_service(self, serviceName, service): + resp = self.__call_api(RangerClient.UPDATE_SERVICE_BY_NAME.format_path({ 'name': serviceName }), request_data=service) + + return type_coerce(resp, RangerService) + + def delete_service_by_id(self, serviceId): + self.__call_api(RangerClient.DELETE_SERVICE_BY_ID.format_path({ 'id': serviceId })) + + def delete_service(self, serviceName): + self.__call_api(RangerClient.DELETE_SERVICE_BY_NAME.format_path({ 'name': serviceName })) + + def find_services(self, filter={}): + resp = self.__call_api(RangerClient.FIND_SERVICES, filter) + + return type_coerce_list(resp, RangerService) + + + # Policy APIs + def create_policy(self, policy): + resp = self.__call_api(RangerClient.CREATE_POLICY, request_data=policy) + + return type_coerce(resp, RangerPolicy) + + def get_policy_by_id(self, policyId): + resp = self.__call_api(RangerClient.GET_POLICY_BY_ID.format_path({ 'id': policyId })) + + return type_coerce(resp, RangerPolicy) + + def get_policy(self, serviceName, policyName): + resp = self.__call_api(RangerClient.GET_POLICY_BY_NAME.format_path({ 'serviceName': serviceName, 'policyName': policyName})) + + return type_coerce(resp, RangerPolicy) + + def get_policies_in_service(self, serviceName): + resp = self.__call_api(RangerClient.GET_POLICIES_IN_SERVICE.format_path({ 'serviceName': serviceName })) + + return type_coerce_list(resp, RangerPolicy) + + def update_policy_by_id(self, policyId, policy): + resp = self.__call_api(RangerClient.UPDATE_POLICY_BY_ID.format_path({ 'id': policyId }), request_data=policy) + + return type_coerce(resp, RangerPolicy) + + def update_policy(self, serviceName, policyName, policy): + resp = self.__call_api(RangerClient.UPDATE_POLICY_BY_NAME.format_path({ 'serviceName': serviceName, 'policyName': policyName}), request_data=policy) + + return type_coerce(resp, RangerPolicy) + + def apply_policy(self, policy): + resp = self.__call_api(RangerClient.APPLY_POLICY, request_data=policy) + + return type_coerce(resp, RangerPolicy) + + def delete_policy_by_id(self, policyId): + self.__call_api(RangerClient.DELETE_POLICY_BY_ID.format_path({ 'id': policyId })) + + def delete_policy(self, serviceName, policyName): + self.__call_api(RangerClient.DELETE_POLICY_BY_NAME, { 'servicename': serviceName, 'policyname': policyName }) + + def find_policies(self, filter={}): + resp = self.__call_api(RangerClient.FIND_POLICIES, filter) + + return type_coerce_list(resp, RangerPolicy) + + + # SecurityZone APIs + def create_security_zone(self, securityZone): + resp = self.__call_api(RangerClient.CREATE_ZONE, request_data=securityZone) + + return type_coerce(resp, RangerSecurityZone) + + def update_security_zone_by_id(self, zoneId, securityZone): + resp = self.__call_api(RangerClient.UPDATE_ZONE_BY_ID.format_path({ 'id': zoneId }), request_data=securityZone) + + return type_coerce(resp, RangerSecurityZone) + + def update_security_zone(self, zoneName, securityZone): + resp = self.__call_api(RangerClient.UPDATE_ZONE_BY_NAME.format_path({ 'name': zoneName }), request_data=securityZone) + + return type_coerce(resp, RangerSecurityZone) + + def delete_security_zone_by_id(self, zoneId): + self.__call_api(RangerClient.DELETE_ZONE_BY_ID.format_path({ 'id': zoneId })) + + def delete_security_zone(self, zoneName): + self.__call_api(RangerClient.DELETE_ZONE_BY_NAME.format_path({ 'name': zoneName })) + + def get_security_zone_by_id(self, zoneId): + resp = self.__call_api(RangerClient.GET_ZONE_BY_ID.format_path({ 'id': zoneId })) + + return type_coerce(resp, RangerSecurityZone) + + def get_security_zone(self, zoneName): + resp = self.__call_api(RangerClient.GET_ZONE_BY_NAME.format_path({ 'name': zoneName })) + + return type_coerce(resp, RangerSecurityZone) + + def find_security_zones(self, filter={}): + resp = self.__call_api(RangerClient.FIND_ZONES, filter) + + return type_coerce_list(resp, RangerSecurityZone) + + + # Role APIs + def create_role(self, serviceName, role): + resp = self.__call_api(RangerClient.CREATE_ROLE, { 'serviceName': serviceName }, role) + + return type_coerce(resp, RangerRole) + + def update_role(self, roleId, role): + resp = self.__call_api(RangerClient.UPDATE_ROLE_BY_ID.format_path({ 'id': roleId }), request_data=role) + + return type_coerce(resp, RangerRole) + + def delete_role_by_id(self, roleId): + self.__call_api(RangerClient.DELETE_ROLE_BY_ID.format_path({ 'id': roleId })) + + def delete_role(self, roleName, execUser, serviceName): + self.__call_api(RangerClient.DELETE_ROLE_BY_NAME.format_path({ 'name': roleName }), { 'execUser': execUser, 'serviceName': serviceName }) + + def get_role_by_id(self, roleId): + resp = self.__call_api(RangerClient.GET_ROLE_BY_ID.format_path({ 'id': roleId })) + + return type_coerce(resp, RangerRole) + + def get_role(self, roleName, execUser, serviceName): + resp = self.__call_api(RangerClient.GET_ROLE_BY_NAME.format_path({ 'name': roleName }), { 'execUser': execUser, 'serviceName': serviceName }) + + return type_coerce(resp, RangerRole) + + def get_all_role_names(self, execUser, serviceName): + resp = self.__call_api(RangerClient.GET_ALL_ROLE_NAMES.format_path({ 'name': serviceName }), { 'execUser': execUser, 'serviceName': serviceName }) + + return resp + + def get_user_roles(self, user): + ret = self.__call_api(RangerClient.GET_USER_ROLES.format_path({ 'name': user })) + + return list(ret) if ret is not None else None + + def find_roles(self, filter={}): + resp = self.__call_api(RangerClient.FIND_ROLES, filter) + + return type_coerce_list(resp, RangerRole) + + def grant_role(self, serviceName, request): + resp = self.__call_api(RangerClient.GRANT_ROLE.format_path({ 'name': serviceName }), request_data=request) + + return type_coerce(resp, RESTResponse) + + def revoke_role(self, serviceName, request): + resp = self.__call_api(RangerClient.REVOKE_ROLE.format_path({ 'name': serviceName }), request_data=request) + + return type_coerce(resp, RESTResponse) + + + # Admin APIs + def delete_policy_deltas(self, days, reloadServicePoliciesCache): + self.__call_api(RangerClient.DELETE_POLICY_DELTAS, { 'days': days, 'reloadServicePoliciesCache': reloadServicePoliciesCache}) + + + + def __call_api(self, api, query_params=None, request_data=None): + ret = None + params = { 'headers': { 'Accept': api.consumes, 'Content-type': api.produces } } + + if query_params: + params['params'] = query_params + + if request_data: + params['data'] = json.dumps(request_data) + + path = os.path.join(self.url, api.path) + + if LOG.isEnabledFor(logging.DEBUG): + LOG.debug("------------------------------------------------------") + LOG.debug("Call : %s %s", api.method, path) + LOG.debug("Content-type : %s", api.consumes) + LOG.debug("Accept : %s", api.produces) + + response = None + + if api.method == HttpMethod.GET: + response = self.session.get(path, **params) + elif api.method == HttpMethod.POST: + response = self.session.post(path, **params) + elif api.method == HttpMethod.PUT: + response = self.session.put(path, **params) + elif api.method == HttpMethod.DELETE: + response = self.session.delete(path, **params) + + if LOG.isEnabledFor(logging.DEBUG): + LOG.debug("HTTP Status: %s", response.status_code if response else "None") + + if response is None: + ret = None + elif response.status_code == api.expected_status: + try: + if response.content: + if LOG.isEnabledFor(logging.DEBUG): + LOG.debug("<== __call_api(%s, %s, %s), result=%s", vars(api), params, request_data, response) + + LOG.debug(response.json()) + + ret = response.json() + else: + ret = None + except Exception as e: + print(e) + + LOG.exception("Exception occurred while parsing response with msg: %s", e) + + raise RangerServiceException(api, response) + elif response.status_code == HTTPStatus.SERVICE_UNAVAILABLE: + LOG.error("Ranger admin unavailable. HTTP Status: %s", HTTPStatus.SERVICE_UNAVAILABLE) + + ret = None + else: + raise RangerServiceException(api, response) + + return ret + + + # URIs + URI_BASE = "service/public/v2/api" + + URI_SERVICEDEF = URI_BASE + "/servicedef" + URI_SERVICEDEF_BY_ID = URI_SERVICEDEF + "/{id}" + URI_SERVICEDEF_BY_NAME = URI_SERVICEDEF + "/name/{name}" + + URI_SERVICE = URI_BASE + "/service" + URI_SERVICE_BY_ID = URI_SERVICE + "/{id}" + URI_SERVICE_BY_NAME = URI_SERVICE + "/name/{name}" + URI_POLICIES_IN_SERVICE = URI_SERVICE + "/{serviceName}/policy" + + URI_POLICY = URI_BASE + "/policy" + URI_APPLY_POLICY = URI_POLICY + "/apply" + URI_POLICY_BY_ID = URI_POLICY + "/{id}" + URI_POLICY_BY_NAME = URI_SERVICE + "/{serviceName}/policy/{policyName}" + + URI_ROLE = URI_BASE + "/roles" + URI_ROLE_NAMES = URI_ROLE + "/names" + URI_ROLE_BY_ID = URI_ROLE + "/{id}" + URI_ROLE_BY_NAME = URI_ROLE + "/name/{name}" + URI_USER_ROLES = URI_ROLE + "/user/{name}" + URI_GRANT_ROLE = URI_ROLE + "/grant/{name}" + URI_REVOKE_ROLE = URI_ROLE + "/revoke/{name}" + + URI_ZONE = URI_BASE + "/zones" + URI_ZONE_BY_ID = URI_ZONE + "/{id}" + URI_ZONE_BY_NAME = URI_ZONE + "/name/{name}" + + URI_PLUGIN_INFO = URI_BASE + "/plugins/info" + URI_POLICY_DELTAS = URI_BASE + "/server/policydeltas" + + # APIs + CREATE_SERVICEDEF = API(URI_SERVICEDEF, HttpMethod.POST, HTTPStatus.OK) + UPDATE_SERVICEDEF_BY_ID = API(URI_SERVICEDEF_BY_ID, HttpMethod.PUT, HTTPStatus.OK) + UPDATE_SERVICEDEF_BY_NAME = API(URI_SERVICEDEF_BY_NAME, HttpMethod.PUT, HTTPStatus.OK) + DELETE_SERVICEDEF_BY_ID = API(URI_SERVICEDEF_BY_ID, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + DELETE_SERVICEDEF_BY_NAME = API(URI_SERVICEDEF_BY_NAME, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + GET_SERVICEDEF_BY_ID = API(URI_SERVICEDEF_BY_ID, HttpMethod.GET, HTTPStatus.OK) + GET_SERVICEDEF_BY_NAME = API(URI_SERVICEDEF_BY_NAME, HttpMethod.GET, HTTPStatus.OK) + FIND_SERVICEDEFS = API(URI_SERVICEDEF, HttpMethod.GET, HTTPStatus.OK) + + CREATE_SERVICE = API(URI_SERVICE, HttpMethod.POST, HTTPStatus.OK) + UPDATE_SERVICE_BY_ID = API(URI_SERVICE_BY_ID, HttpMethod.PUT, HTTPStatus.OK) + UPDATE_SERVICE_BY_NAME = API(URI_SERVICE_BY_NAME, HttpMethod.PUT, HTTPStatus.OK) + DELETE_SERVICE_BY_ID = API(URI_SERVICE_BY_ID, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + DELETE_SERVICE_BY_NAME = API(URI_SERVICE_BY_NAME, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + GET_SERVICE_BY_ID = API(URI_SERVICE_BY_ID, HttpMethod.GET, HTTPStatus.OK) + GET_SERVICE_BY_NAME = API(URI_SERVICE_BY_NAME, HttpMethod.GET, HTTPStatus.OK) + FIND_SERVICES = API(URI_SERVICE, HttpMethod.GET, HTTPStatus.OK) + + CREATE_POLICY = API(URI_POLICY, HttpMethod.POST, HTTPStatus.OK) + UPDATE_POLICY_BY_ID = API(URI_POLICY_BY_ID, HttpMethod.PUT, HTTPStatus.OK) + UPDATE_POLICY_BY_NAME = API(URI_POLICY_BY_NAME, HttpMethod.PUT, HTTPStatus.OK) + APPLY_POLICY = API(URI_APPLY_POLICY, HttpMethod.POST, HTTPStatus.OK) + DELETE_POLICY_BY_ID = API(URI_POLICY_BY_ID, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + DELETE_POLICY_BY_NAME = API(URI_POLICY, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + GET_POLICY_BY_ID = API(URI_POLICY_BY_ID, HttpMethod.GET, HTTPStatus.OK) + GET_POLICY_BY_NAME = API(URI_POLICY_BY_NAME, HttpMethod.GET, HTTPStatus.OK) + GET_POLICIES_IN_SERVICE = API(URI_POLICIES_IN_SERVICE, HttpMethod.GET, HTTPStatus.OK) + FIND_POLICIES = API(URI_POLICY, HttpMethod.GET, HTTPStatus.OK) + + CREATE_ZONE = API(URI_ZONE, HttpMethod.POST, HTTPStatus.OK) + UPDATE_ZONE_BY_ID = API(URI_ZONE_BY_ID, HttpMethod.PUT, HTTPStatus.OK) + UPDATE_ZONE_BY_NAME = API(URI_ZONE_BY_NAME, HttpMethod.PUT, HTTPStatus.OK) + DELETE_ZONE_BY_ID = API(URI_ZONE_BY_ID, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + DELETE_ZONE_BY_NAME = API(URI_ZONE_BY_NAME, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + GET_ZONE_BY_ID = API(URI_ZONE_BY_ID, HttpMethod.GET, HTTPStatus.OK) + GET_ZONE_BY_NAME = API(URI_ZONE_BY_NAME, HttpMethod.GET, HTTPStatus.OK) + FIND_ZONES = API(URI_ZONE, HttpMethod.GET, HTTPStatus.OK) + + CREATE_ROLE = API(URI_ROLE, HttpMethod.POST, HTTPStatus.OK) + UPDATE_ROLE_BY_ID = API(URI_ROLE_BY_ID, HttpMethod.PUT, HTTPStatus.OK) + DELETE_ROLE_BY_ID = API(URI_ROLE_BY_ID, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + DELETE_ROLE_BY_NAME = API(URI_ROLE_BY_NAME, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + GET_ROLE_BY_ID = API(URI_ROLE_BY_ID, HttpMethod.GET, HTTPStatus.OK) + GET_ROLE_BY_NAME = API(URI_ROLE_BY_NAME, HttpMethod.GET, HTTPStatus.OK) + GET_ALL_ROLE_NAMES = API(URI_ROLE_NAMES, HttpMethod.GET, HTTPStatus.OK) + GET_USER_ROLES = API(URI_USER_ROLES, HttpMethod.GET, HTTPStatus.OK) + GRANT_ROLE = API(URI_GRANT_ROLE, HttpMethod.PUT, HTTPStatus.OK) + REVOKE_ROLE = API(URI_REVOKE_ROLE, HttpMethod.PUT, HTTPStatus.OK) + FIND_ROLES = API(URI_ROLE, HttpMethod.GET, HTTPStatus.OK) + + GET_PLUGIN_INFO = API(URI_PLUGIN_INFO, HttpMethod.GET, HTTPStatus.OK) + DELETE_POLICY_DELTAS = API(URI_POLICY_DELTAS, HttpMethod.DELETE, HTTPStatus.NO_CONTENT) + + +class Message(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.name = attrs.get('name') + self.rbKey = attrs.get('rbKey') + self.message = attrs.get('message') + self.objectId = attrs.get('objectId') + self.fieldName = attrs.get('fieldName') + + +class RESTResponse(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.httpStatusCode = attrs.get('httpStatusCode') + self.statusCode = attrs.get('statusCode') + self.msgDesc = attrs.get('msgDesc') + self.messageList = non_null(attrs.get('messageList'), []) + + def type_coerce_attrs(self): + super(RangerPolicy, self).type_coerce_attrs() + + self.messageList = type_coerce_dict(self.messageList, Message) diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/exceptions.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/exceptions.py new file mode 100644 index 00000000000..a2299479c2f --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/exceptions.py @@ -0,0 +1,45 @@ +#!/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. + + +class RangerServiceException(Exception): + """Exception raised for errors in API calls. + + Attributes: + api -- api endpoint which caused the error + response -- response from the server + """ + + def __init__(self, api, response): + self.method = api.method.name + self.path = api.path + self.expected_status = api.expected_status + self.statusCode = -1 + self.msgDesc = None + self.messageList = None + + print(response) + + if api is not None and response is not None: + respJson = response.json() + + self.statusCode = response.status_code + self.msgDesc = respJson['msgDesc'] if respJson is not None and 'msgDesc' in respJson else None + self.messageList = respJson['messageList'] if respJson is not None and 'messageList' in respJson else None + + Exception.__init__(self, "{} {} failed: expected_status={}, status={}, message={}".format(self.method, self.path, self.expected_status, self.statusCode, self.msgDesc)) diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/__init__.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/__init__.py new file mode 100644 index 00000000000..ed9d0b3c4e8 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/__init__.py @@ -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. diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/grant_revoke_role_request.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/grant_revoke_role_request.py new file mode 100644 index 00000000000..fcc907844ab --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/grant_revoke_role_request.py @@ -0,0 +1,39 @@ +#!/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. + +from apache_ranger.model.ranger_base import * +from apache_ranger.utils import * + + +class GrantRevokeRoleRequest(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.grantor = attrs.get('grantor') + self.grantorGroups = attrs.get('grantorGroups') + self.targetRoles = attrs.get('targetRoles') + self.users = attrs.get('users') + self.groups = attrs.get('groups') + self.roles = attrs.get('roles') + self.grantOption = non_null(attrs.get('grantOption'), False) + self.clientIPAddress = attrs.get('clientIPAddress') + self.clientType = attrs.get('clientType') + self.requestData = attrs.get('requestData') + self.sessionId = attrs.get('sessionId') + self.clusterName = attrs.get('clusterName') + diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_base.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_base.py new file mode 100644 index 00000000000..edabe2c0a9f --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_base.py @@ -0,0 +1,63 @@ +#!/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. + +import json + +from apache_ranger.utils import * + + +class RangerBase(dict): + def __init__(self, attrs): + pass + + def __getattr__(self, attr): + return self.get(attr) + + def __setattr__(self, key, value): + self.__setitem__(key, value) + + def __setitem__(self, key, value): + super(RangerBase, self).__setitem__(key, value) + self.__dict__.update({key: value}) + + def __delattr__(self, item): + self.__delitem__(item) + + def __delitem__(self, key): + super(RangerBase, self).__delitem__(key) + del self.__dict__[key] + + def __repr__(self): + return json.dumps(self) + + def type_coerce_attrs(self): + pass + + +class RangerBaseModelObject(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.id = attrs.get('id') + self.guid = attrs.get('guid') + self.isEnabled = non_null(attrs.get('isEnabled'), True) + self.createdBy = attrs.get('createdBy') + self.updatedBy = attrs.get('updatedBy') + self.createTime = attrs.get('createTime') + self.updateTime = attrs.get('updateTime') + self.version = attrs.get('version') diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_policy.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_policy.py new file mode 100644 index 00000000000..1531a842a02 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_policy.py @@ -0,0 +1,155 @@ +#!/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. + + +from apache_ranger.model.ranger_base import * +from apache_ranger.utils import * + + +class RangerPolicy(RangerBaseModelObject): + POLICY_TYPE_ACCESS = 0 + POLICY_TYPE_DATAMASK = 1 + POLICY_TYPE_ROWFILTER = 2 + + def __init__(self, attrs={}): + RangerBaseModelObject.__init__(self, attrs) + + self.service = attrs.get('service') + self.name = attrs.get('name') + self.policyType = attrs.get('policyType') + self.policyPriority = attrs.get('policyPriority') + self.description = attrs.get('description') + self.resourceSignature = attrs.get('resourceSignature') + self.isAuditEnabled = attrs.get('isAuditEnabled') + self.resources = attrs.get('resources') + self.policyItems = attrs.get('policyItems') + self.denyPolicyItems = attrs.get('denyPolicyItems') + self.allowExceptions = attrs.get('allowExceptions') + self.denyExceptions = attrs.get('denyExceptions') + self.dataMaskPolicyItems = attrs.get('dataMaskPolicyItems') + self.rowFilterPolicyItems = attrs.get('rowFilterPolicyItems') + self.serviceType = attrs.get('serviceType') + self.options = attrs.get('options') + self.validitySchedules = attrs.get('validitySchedules') + self.policyLabels = attrs.get('policyLabels') + self.zoneName = attrs.get('zoneName') + self.conditions = attrs.get('conditions') + self.isDenyAllElse = non_null(attrs.get('isDenyAllElse'), False) + + def type_coerce_attrs(self): + super(RangerPolicy, self).type_coerce_attrs() + + self.resources = type_coerce_dict(self.resources, RangerPolicyResource) + self.policyItems = type_coerce_list(self.policyItems, RangerPolicyItem) + self.denyPolicyItems = type_coerce_list(self.denyPolicyItems, RangerPolicyItem) + self.allowExceptions = type_coerce_list(self.allowExceptions, RangerPolicyItem) + self.denyExceptions = type_coerce_list(self.denyExceptions, RangerPolicyItem) + self.dataMaskPolicyItems = type_coerce_list(self.dataMaskPolicyItems, RangerDataMaskPolicyItem) + self.rowFilterPolicyItems = type_coerce_list(self.rowFilterPolicyItems, RangerRowFilterPolicyItem) + self.validitySchedules = type_coerce_list(self.validitySchedules, RangerValiditySchedule) + + +class RangerPolicyResource(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.values = attrs.get('values') + self.isExcludes = non_null(attrs.get('isExcludes'), False) + self.isRecursive = non_null(attrs.get('isRecursive'), False) + + +class RangerPolicyItemCondition(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.type = attrs.get('type') + self.values = attrs.get('values') + + +class RangerPolicyItem(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.accesses = attrs.get('accesses') + self.users = attrs.get('users') + self.groups = attrs.get('groups') + self.roles = attrs.get('roles') + self.conditions = attrs.get('conditions') + self.delegateAdmin = non_null(attrs.get('delegateAdmin'), False) + + def type_coerce_attrs(self): + super(RangerPolicyItem, self).type_coerce_attrs() + + self.accesses = type_coerce_list(self.accesses, RangerPolicyItemAccess) + + +class RangerDataMaskPolicyItem(RangerPolicyItem): + def __init__(self, attrs={}): + RangerPolicyItem.__init__(self, attrs) + + self.dataMaskInfo = attrs.get('dataMaskInfo') + + def type_coerce_attrs(self): + super(RangerDataMaskPolicyItem, self).type_coerce_attrs() + + self.dataMaskInfo = type_coerce(self.dataMaskInfo, RangerPolicyItemDataMaskInfo) + + +class RangerRowFilterPolicyItem(RangerPolicyItem): + def __init__(self, attrs={}): + RangerPolicyItem.__init__(self, attrs) + + self.rowFilterInfo = attrs.get('rowFilterInfo') + + def type_coerce_attrs(self): + super(RangerRowFilterPolicyItem, self).type_coerce_attrs() + + self.rowFilterInfo = type_coerce(self.rowFilterInfo, RangerPolicyItemRowFilterInfo) + + +class RangerValiditySchedule(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.startTime = attrs.get('startTime') + self.endTime = attrs.get('endTime') + self.timeZone = attrs.get('timeZone') + + +class RangerPolicyItemAccess(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.type = attrs.get('type') + self.isAllowed = non_null(attrs.get('isAllowed'), True) + + +class RangerPolicyItemDataMaskInfo(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.dataMaskType = attrs.get('dataMaskType') + self.conditionExpr = attrs.get('conditionExpr') + self.valueExpr = attrs.get('valueExpr') + + +class RangerPolicyItemRowFilterInfo(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.filterExpr = attrs.get('filterExpr') diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_role.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_role.py new file mode 100644 index 00000000000..c789a76b3b7 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_role.py @@ -0,0 +1,41 @@ +#!/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. + +from apache_ranger.model.ranger_base import RangerBase, RangerBaseModelObject +from apache_ranger.utils import * + + +class RoleMember(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.name = attrs.get('name') + self.isAdmin = non_null(attrs.get('isAdmin'), False) + + +class RangerRole(RangerBaseModelObject): + def __init__(self, attrs={}): + RangerBaseModelObject.__init__(self, attrs) + + self.name = attrs.get('name') + self.description = attrs.get('description') + self.options = attrs.get('options') + self.users = attrs.get('users') + self.groups = attrs.get('groups') + self.roles = attrs.get('roles') + self.createdByUser = attrs.get('createdByUser') diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_security_zone.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_security_zone.py new file mode 100644 index 00000000000..2ba0915d810 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_security_zone.py @@ -0,0 +1,40 @@ +#!/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. + +from apache_ranger.model.ranger_base import RangerBase, RangerBaseModelObject + + +class RangerSecurityZoneService(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.resources = attrs.get('resources') + + +class RangerSecurityZone(RangerBaseModelObject): + def __init__(self, attrs={}): + RangerBaseModelObject.__init__(self, attrs) + + self.name = attrs.get('name') + self.services = attrs.get('services') + self.tagServices = attrs.get('tagServices') + self.adminUsers = attrs.get('adminUsers') + self.adminUserGroups = attrs.get('adminUserGroups') + self.auditUsers = attrs.get('auditUsers') + self.auditUserGroups = attrs.get('auditUserGroups') + self.description = attrs.get('description') diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_service.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_service.py new file mode 100644 index 00000000000..d8ea93b9a96 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_service.py @@ -0,0 +1,35 @@ +#!/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. + +from apache_ranger.model.ranger_base import RangerBaseModelObject + + +class RangerService(RangerBaseModelObject): + def __init__(self, attrs={}): + RangerBaseModelObject.__init__(self, attrs) + + self.type = attrs.get('type') + self.name = attrs.get('name') + self.displayName = attrs.get('displayName') + self.description = attrs.get('description') + self.tagService = attrs.get('tagService') + self.configs = attrs.get('configs') + self.policyVersion = attrs.get('policyVersion') + self.policyUpdateTime = attrs.get('policyUpdateTime') + self.tagVersion = attrs.get('tagVersion') + self.tagUpdateTime = attrs.get('tagUpdateTime') diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_service_def.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_service_def.py new file mode 100644 index 00000000000..b35fe2a9db6 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/model/ranger_service_def.py @@ -0,0 +1,209 @@ +#!/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. + +from apache_ranger.model.ranger_base import RangerBase, RangerBaseModelObject +from apache_ranger.utils import * + + +class RangerServiceDef(RangerBaseModelObject): + def __init__(self, attrs={}): + RangerBaseModelObject.__init__(self, attrs) + + self.name = attrs.get('name') + self.displayName = attrs.get('displayName') + self.implClass = attrs.get('implClass') + self.label = attrs.get('label') + self.description = attrs.get('description') + self.rbKeyLabel = attrs.get('rbKeyLabel') + self.rbKeyDescription = attrs.get('rbKeyDescription') + self.options = attrs.get('options') + self.configs = attrs.get('configs') + self.resources = attrs.get('resources') + self.accessTypes = attrs.get('accessTypes') + self.policyConditions = attrs.get('policyConditions') + self.contextEnrichers = attrs.get('contextEnrichers') + self.enums = attrs.get('enums') + self.dataMaskDef = attrs.get('dataMaskDef') + self.rowFilterDef = attrs.get('rowFilterDef') + + def type_coerce_attrs(self): + super(RangerServiceDef, self).type_coerce_attrs() + + self.configs = type_coerce_list(self.configs, RangerResourceDef) + self.resources = type_coerce_list(self.resources, RangerResourceDef) + self.accessTypes = type_coerce_list(self.accessTypes, RangerAccessTypeDef) + self.policyConditions = type_coerce_list(self.policyConditions, RangerPolicyConditionDef) + self.contextEnrichers = type_coerce_list(self.contextEnrichers, RangerContextEnricherDef) + self.enums = type_coerce_list(self.enums, RangerEnumDef) + self.dataMaskDef = type_coerce(self.dataMaskDef, RangerDataMaskDef) + self.rowFilterDef = type_coerce(self.rowFilterDef, RangerRowFilterDef) + + +class RangerServiceConfigDef: + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.itemId = attrs.get('itemId') + self.name = attrs.get('name') + self.type = attrs.get('type') + self.subType = attrs.get('subType') + self.mandatory = attrs.get('mandatory') + self.defaultValue = attrs.get('defaultValue') + self.validationRegEx = attrs.get('validationRegEx') + self.validationMessage = attrs.get('validationMessage') + self.uiHint = attrs.get('uiHint') + self.label = attrs.get('label') + self.description = attrs.get('description') + self.rbKeyLabel = attrs.get('rbKeyLabel') + self.rbKeyDescription = attrs.get('rbKeyDescription') + self.rbKeyValidationMessage = attrs.get('rbKeyValidationMessage') + + +class RangerResourceDef(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.itemId = attrs.get('itemId') + self.name = attrs.get('name') + self.type = attrs.get('type') + self.level = non_null(attrs.get('level'), 1) + self.parent = attrs.get('parent') + self.mandatory = attrs.get('mandatory') + self.lookupSupported = attrs.get('lookupSupported') + self.recursiveSupported = attrs.get('recursiveSupported') + self.excludesSupported = attrs.get('excludesSupported') + self.matcher = attrs.get('matcher') + self.matcherOptions = attrs.get('matcherOptions') + self.validationRegEx = attrs.get('validationRegEx') + self.validationMessage = attrs.get('validationMessage') + self.uiHint = attrs.get('uiHint') + self.label = attrs.get('label') + self.description = attrs.get('description') + self.rbKeyLabel = attrs.get('rbKeyLabel') + self.rbKeyDescription = attrs.get('rbKeyDescription') + self.rbKeyValidationMessage = attrs.get('rbKeyValidationMessage') + self.accessTypeRestrictions = attrs.get('accessTypeRestrictions') + self.isValidLeaf = attrs.get('isValidLeaf') + + +class RangerAccessTypeDef(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.itemId = attrs.get('itemId') + self.name = attrs.get('name') + self.label = attrs.get('label') + self.rbKeyLabel = attrs.get('rbKeyLabel') + self.impliedGrants = attrs.get('impliedGrants') + + +class RangerPolicyConditionDef(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.itemId = attrs.get('itemId') + self.name = attrs.get('name') + self.evaluator = attrs.get('evaluator') + self.evaluatorOptions = attrs.get('evaluatorOptions') + self.validationRegEx = attrs.get('validationRegEx') + self.validationMessage = attrs.get('validationMessage') + self.uiHint = attrs.get('uiHint') + self.label = attrs.get('label') + self.description = attrs.get('description') + self.rbKeyLabel = attrs.get('rbKeyLabel') + self.rbKeyDescription = attrs.get('rbKeyDescription') + self.rbKeyValidationMessage = attrs.get('rbKeyValidationMessage') + + +class RangerContextEnricherDef(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.itemId = attrs.get('itemId') + self.name = attrs.get('name') + self.enricher = attrs.get('enricher') + self.enricherOptions = attrs.get('enricherOptions') + + +class RangerEnumDef(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.itemId = attrs.get('itemId') + self.name = attrs.get('name') + self.elements = attrs.get('elements') + self.defaultIndex = attrs.get('defaultIndex') + + def type_coerce_attrs(self): + super(RangerEnumDef, self).type_coerce_attrs() + + self.elements = type_coerce_list(self.resources, RangerEnumElementDef) + + +class RangerDataMaskDef(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.maskTypes = attrs.get('maskTypes') + self.accessTypes = attrs.get('accessTypes') + self.resources = attrs.get('resources') + + def type_coerce_attrs(self): + super(RangerDataMaskDef, self).type_coerce_attrs() + + self.maskTypes = type_coerce_list(self.maskTypes, RangerDataMaskTypeDef) + self.accessTypes = type_coerce_list(self.accessTypes, RangerAccessTypeDef) + self.resources = type_coerce_list(self.resources, RangerResourceDef) + + +class RangerRowFilterDef(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.accessTypes = attrs.get('accessTypes') + self.resources = attrs.get('resources') + + def type_coerce_attrs(self): + super(RangerRowFilterDef, self).type_coerce_attrs() + + self.accessTypes = type_coerce_list(self.accessTypes, RangerAccessTypeDef) + self.resources = type_coerce_list(self.accessTypes, RangerResourceDef) + + +class RangerEnumElementDef(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.itemId = attrs.get('itemId') + self.name = attrs.get('name') + self.label = attrs.get('label') + self.rbKeyLabel = attrs.get('rbKeyLabel') + + +class RangerDataMaskTypeDef(RangerBase): + def __init__(self, attrs={}): + RangerBase.__init__(self, attrs) + + self.itemId = attrs.get('itemId') + self.name = attrs.get('name') + self.label = attrs.get('label') + self.description = attrs.get('description') + self.transformer = attrs.get('transformer') + self.dataMaskOptions = attrs.get('dataMaskOptions') + self.rbKeyLabel = attrs.get('rbKeyLabel') + self.rbKeyDescription = attrs.get('rbKeyDescription') diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/utils.py b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/utils.py new file mode 100644 index 00000000000..4c7e77fe6c2 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/apache_ranger/utils.py @@ -0,0 +1,92 @@ +#!/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. + +import enum + +APPLICATION_JSON = 'application/json' + + +def non_null(obj, defValue): + return obj if obj is not None else defValue + +def type_coerce(obj, objType): + if isinstance(obj, objType): + ret = obj + elif isinstance(obj, dict): + ret = objType(obj) + + ret.type_coerce_attrs() + else: + ret = None + + return ret + +def type_coerce_list(obj, objType): + if isinstance(obj, list): + ret = [] + for entry in obj: + ret.append(type_coerce(entry, objType)) + else: + ret = None + + return ret + +def type_coerce_dict(obj, objType): + if isinstance(obj, dict): + ret = {} + for k, v in obj.items(): + ret[k] = type_coerce(v, objType) + else: + ret = None + + return ret + +def type_coerce_dict_list(obj, objType): + if isinstance(obj, dict): + ret = {} + for k, v in obj.items(): + ret[k] = type_coerce_list(v, objType) + else: + ret = None + + return ret + + +class API: + def __init__(self, path, method, expected_status, consumes=APPLICATION_JSON, produces=APPLICATION_JSON): + self.path = path + self.method = method + self.expected_status = expected_status + self.consumes = consumes + self.produces = produces + + def format_path(self, params): + return API(self.path.format(**params), self.method, self.expected_status, self.consumes, self.produces) + + +class HttpMethod(enum.Enum): + GET = "GET" + PUT = "PUT" + POST = "POST" + DELETE = "DELETE" + + +class HTTPStatus: + OK = 200 + NO_CONTENT = 204 + SERVICE_UNAVAILABLE = 503 diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/setup.cfg b/desktop/core/ext-py/apache-ranger-0.0.3/setup.cfg new file mode 100644 index 00000000000..8bfd5a12f85 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/setup.cfg @@ -0,0 +1,4 @@ +[egg_info] +tag_build = +tag_date = 0 + diff --git a/desktop/core/ext-py/apache-ranger-0.0.3/setup.py b/desktop/core/ext-py/apache-ranger-0.0.3/setup.py new file mode 100644 index 00000000000..5a976571336 --- /dev/null +++ b/desktop/core/ext-py/apache-ranger-0.0.3/setup.py @@ -0,0 +1,49 @@ +#!/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. + +from setuptools import setup, find_packages + +# External dependencies +requirements = ['requests>=2.24'] + +long_description = '' +with open("README.md", "r") as fh: + long_description = fh.read() + +setup( + name="apache-ranger", + version="0.0.3", + 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", + license='Apache LICENSE 2.0', + classifiers=[ + "Programming Language :: Python :: 2.7", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + ], + packages=find_packages(), + install_requires=requirements, + include_package_data=True, + zip_safe=False, + keywords='ranger client, apache ranger', + python_requires='>=2.7', +) diff --git a/desktop/core/requirements.txt b/desktop/core/requirements.txt index 99eebcc108d..7282ffab32e 100644 --- a/desktop/core/requirements.txt +++ b/desktop/core/requirements.txt @@ -1,3 +1,4 @@ +apache-ranger==0.0.3 asn1crypto==0.24.0 avro-python3==1.8.2 Babel==2.5.1