This is an automated email from the ASF dual-hosted git repository. madhan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ranger.git
commit e6bb0df9ca0f10f6192b60ecb558df6c7a9ac3fb Author: Madhan Neethiraj <[email protected]> AuthorDate: Sun Feb 12 13:54:51 2023 -0800 RANGER-4080: Python client updated with addition of 2 security-zone APIs --- intg/src/main/python/README.md | 2 +- .../python/apache_ranger/client/ranger_client.py | 29 ++++++++++++++-------- .../apache_ranger/model/ranger_security_zone.py | 20 +++++++++++++++ .../python/apache_ranger/model/ranger_service.py | 11 ++++++++ intg/src/main/python/apache_ranger/utils.py | 16 ++++++------ intg/src/main/python/setup.py | 2 +- 6 files changed, 60 insertions(+), 20 deletions(-) diff --git a/intg/src/main/python/README.md b/intg/src/main/python/README.md index 46de769fc..3df8aa696 100644 --- a/intg/src/main/python/README.md +++ b/intg/src/main/python/README.md @@ -35,7 +35,7 @@ Verify if apache-ranger client is installed: Package Version ------------ --------- -apache-ranger 0.0.8 +apache-ranger 0.0.10 ``` ## Usage diff --git a/intg/src/main/python/apache_ranger/client/ranger_client.py b/intg/src/main/python/apache_ranger/client/ranger_client.py index 260095b2f..4680e2d8e 100644 --- a/intg/src/main/python/apache_ranger/client/ranger_client.py +++ b/intg/src/main/python/apache_ranger/client/ranger_client.py @@ -23,8 +23,8 @@ from apache_ranger.exceptions import RangerServiceException from apache_ranger.model.ranger_base import RangerBase from apache_ranger.model.ranger_policy import RangerPolicy from apache_ranger.model.ranger_role import RangerRole -from apache_ranger.model.ranger_security_zone import RangerSecurityZone -from apache_ranger.model.ranger_service import RangerService +from apache_ranger.model.ranger_security_zone import RangerSecurityZone, RangerSecurityZoneHeaderInfo +from apache_ranger.model.ranger_service import RangerService, RangerServiceHeaderInfo from apache_ranger.model.ranger_service_def import RangerServiceDef from apache_ranger.model.ranger_service_tags import RangerServiceTags from apache_ranger.utils import * @@ -194,11 +194,6 @@ class RangerClient: return type_coerce(resp, RangerSecurityZone) - def update_security_zone(self, zoneName, securityZone): - resp = self.client_http.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.client_http.call_api(RangerClient.DELETE_ZONE_BY_ID.format_path({ 'id': zoneId })) @@ -215,6 +210,16 @@ class RangerClient: return type_coerce(resp, RangerSecurityZone) + def get_security_zone_headers(self): + resp = self.client_http.call_api(RangerClient.GET_ZONE_HEADERS) + + return type_coerce_list(resp, RangerSecurityZoneHeaderInfo) + + def get_security_zone_service_headers(self, zoneId): + resp = self.client_http.call_api(RangerClient.GET_ZONE_SERVICE_HEADERS.format_path({ 'id': zoneId })) + + return type_coerce_list(resp, RangerServiceHeaderInfo) + def find_security_zones(self, filter=None): resp = self.client_http.call_api(RangerClient.FIND_ZONES, filter) @@ -320,9 +325,11 @@ class RangerClient: 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_ZONE = URI_BASE + "/zones" + URI_ZONE_BY_ID = URI_ZONE + "/{id}" + URI_ZONE_BY_NAME = URI_ZONE + "/name/{name}" + URI_ZONE_HEADERS = URI_BASE + "/zone-headers" + URI_ZONE_SERVICE_HEADERS = URI_ZONE + "/{id}/service-headers" URI_SERVICE_TAGS = URI_SERVICE + "/{serviceName}/tags" URI_PLUGIN_INFO = URI_BASE + "/plugins/info" @@ -366,6 +373,8 @@ class RangerClient: 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) + GET_ZONE_HEADERS = API(URI_ZONE_HEADERS, HttpMethod.GET, HTTPStatus.OK) + GET_ZONE_SERVICE_HEADERS = API(URI_ZONE_SERVICE_HEADERS, 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) diff --git a/intg/src/main/python/apache_ranger/model/ranger_security_zone.py b/intg/src/main/python/apache_ranger/model/ranger_security_zone.py index 3056b7ed5..9b3eec623 100644 --- a/intg/src/main/python/apache_ranger/model/ranger_security_zone.py +++ b/intg/src/main/python/apache_ranger/model/ranger_security_zone.py @@ -17,6 +17,7 @@ # limitations under the License. from apache_ranger.model.ranger_base import RangerBase, RangerBaseModelObject +from apache_ranger.utils import * class RangerSecurityZoneService(RangerBase): @@ -28,6 +29,11 @@ class RangerSecurityZoneService(RangerBase): self.resources = attrs.get('resources') + def type_coerce_attrs(self): + super(RangerSecurityZoneService, self).type_coerce_attrs() + + self.resources = type_coerce_list_dict(self.resources, list) + class RangerSecurityZone(RangerBaseModelObject): def __init__(self, attrs=None): @@ -44,3 +50,17 @@ class RangerSecurityZone(RangerBaseModelObject): self.auditUsers = attrs.get('auditUsers') self.auditUserGroups = attrs.get('auditUserGroups') self.description = attrs.get('description') + + def type_coerce_attrs(self): + super(RangerSecurityZone, self).type_coerce_attrs() + + self.services = type_coerce_dict(self.services, RangerSecurityZoneService) + +class RangerSecurityZoneHeaderInfo(RangerBaseModelObject): + def __init__(self, attrs=None): + if attrs is None: + attrs = {} + + RangerBaseModelObject.__init__(self, attrs) + + self.name = attrs.get('name') diff --git a/intg/src/main/python/apache_ranger/model/ranger_service.py b/intg/src/main/python/apache_ranger/model/ranger_service.py index a3d273c20..a1346d5b5 100644 --- a/intg/src/main/python/apache_ranger/model/ranger_service.py +++ b/intg/src/main/python/apache_ranger/model/ranger_service.py @@ -36,3 +36,14 @@ class RangerService(RangerBaseModelObject): self.policyUpdateTime = attrs.get('policyUpdateTime') self.tagVersion = attrs.get('tagVersion') self.tagUpdateTime = attrs.get('tagUpdateTime') + + +class RangerServiceHeaderInfo(RangerBaseModelObject): + def __init__(self, attrs=None): + if attrs is None: + attrs = {} + + RangerBaseModelObject.__init__(self, attrs) + + self.name = attrs.get('name') + self.isTagService = attrs.get('isTagService') diff --git a/intg/src/main/python/apache_ranger/utils.py b/intg/src/main/python/apache_ranger/utils.py index b3c568f1f..28e0e4b60 100644 --- a/intg/src/main/python/apache_ranger/utils.py +++ b/intg/src/main/python/apache_ranger/utils.py @@ -30,7 +30,8 @@ def type_coerce(obj, objType): elif isinstance(obj, dict): ret = objType(obj) - ret.type_coerce_attrs() + if callable(getattr(ret, 'type_coerce_attrs', None)): + ret.type_coerce_attrs() else: ret = None @@ -38,13 +39,8 @@ def type_coerce(obj, objType): 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 + return [ type_coerce(entry, objType) for entry in obj ] + return None def type_coerce_dict(obj, objType): if isinstance(obj, dict): @@ -66,6 +62,10 @@ def type_coerce_dict_list(obj, objType): return ret +def type_coerce_list_dict(obj, objType): + if isinstance(obj, list): + return [ type_coerce_dict(entry, objType) for entry in obj ] + return None class API: def __init__(self, path, method, expected_status, consumes=APPLICATION_JSON, produces=APPLICATION_JSON): diff --git a/intg/src/main/python/setup.py b/intg/src/main/python/setup.py index 5222d7153..dbb11617d 100644 --- a/intg/src/main/python/setup.py +++ b/intg/src/main/python/setup.py @@ -27,7 +27,7 @@ with open("README.md", "r") as fh: setup( name="apache-ranger", - version="0.0.8", + version="0.0.10", author="Apache Ranger", author_email="[email protected]", description="Apache Ranger Python client",
