Skip to content

Commit

Permalink
RANGER-4446: updated Python client with get_dataset_summary() API - #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mneethiraj committed Oct 8, 2023
1 parent 39b6d67 commit 789d696
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def get_dataset_names(self, filter=None):

return PList(resp).type_coerce_list(str)

def get_dataset_summary(self, filter=None):
resp = self.client_http.call_api(RangerGdsClient.GET_DATASET_SUMMARY, filter)

return PList(resp).type_coerce_list(DatasetSummary)

def add_dataset_policy(self, datasetId, policy):
resp = self.client_http.call_api(RangerGdsClient.ADD_DATASET_POLICY.format_path({ 'id': datasetId }), request_data=policy)

Expand Down Expand Up @@ -248,6 +253,7 @@ def find_dataset_in_projects(self, filter=None):
URI_DATASET = URI_GDS + "/dataset"
URI_DATASET_BY_ID = URI_DATASET + "/{id}"
URI_DATASET_NAMES = URI_DATASET + "/names"
URI_DATASET_SUMMARY = URI_DATASET + "/summary"
URI_DATASET_POLICY = URI_DATASET_BY_ID + "/policy"
URI_DATASET_POLICY_ID = URI_DATASET_POLICY + "/{policyId}"
URI_PROJECT = URI_GDS + "/project"
Expand Down Expand Up @@ -275,6 +281,7 @@ def find_dataset_in_projects(self, filter=None):
GET_DATASET_BY_ID = API(URI_DATASET_BY_ID, HttpMethod.GET, HTTPStatus.OK)
FIND_DATASETS = API(URI_DATASET, HttpMethod.GET, HTTPStatus.OK)
GET_DATASET_NAMES = API(URI_DATASET_NAMES, HttpMethod.GET, HTTPStatus.OK)
GET_DATASET_SUMMARY = API(URI_DATASET_SUMMARY, HttpMethod.GET, HTTPStatus.OK)
ADD_DATASET_POLICY = API(URI_DATASET_POLICY, HttpMethod.POST, HTTPStatus.OK)
UPDATE_DATASET_POLICY = API(URI_DATASET_POLICY_ID, HttpMethod.PUT, HTTPStatus.OK)
DELETE_DATASET_POLICY = API(URI_DATASET_POLICY_ID, HttpMethod.DELETE, HTTPStatus.NO_CONTENT)
Expand Down Expand Up @@ -315,4 +322,4 @@ def find_dataset_in_projects(self, filter=None):
UPDATE_DATASET_IN_PROJECT_BY_ID = API(URI_DATASET_PROJECT_BY_ID, HttpMethod.PUT, HTTPStatus.OK)
REMOVE_DATASET_IN_PROJECT_BY_ID = API(URI_DATASET_PROJECT_BY_ID, HttpMethod.DELETE, HTTPStatus.NO_CONTENT)
GET_DATASET_IN_PROJECT_BY_ID = API(URI_DATASET_PROJECT_BY_ID, HttpMethod.GET, HTTPStatus.OK)
FIND_DATASET_IN_PROJECTS = API(URI_DATASET_PROJECT, HttpMethod.GET, HTTPStatus.OK)
FIND_DATASET_IN_PROJECTS = API(URI_DATASET_PROJECT, HttpMethod.GET, HTTPStatus.OK)
61 changes: 53 additions & 8 deletions intg/src/main/python/apache_ranger/model/ranger_gds.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

from apache_ranger.model.ranger_base import RangerBase, RangerBaseModelObject
from apache_ranger.model.ranger_policy import *
from apache_ranger.model.ranger_principal import RangerPrincipal
from apache_ranger.model.ranger_principal import *
from apache_ranger.utils import *

class GdsPermission(StrEnum):
NONE = 'NONE'
LIST = 'LIST'
VIEW = 'VIEW'
AUDIT = 'AUDIT'
ADMIN = 'ADMIN'
NONE = 'NONE'
LIST = 'LIST'
VIEW = 'VIEW'
AUDIT = 'AUDIT'
POLICY_ADMIN = 'POLICY_ADMIN'
ADMIN = 'ADMIN'

@classmethod
def value_of(cls, val):
Expand All @@ -36,8 +37,7 @@ def value_of(cls, val):
for key, member in cls.__members__.items():
if val == member.name or val == member.value:
return member
else:
raise ValueError(f"'{cls.__name__}' enum not found for '{val}'")
raise ValueError(f"'{cls.__name__}' enum not found for '{val}'")

class GdsShareStatus(StrEnum):
NONE = 'NONE'
Expand Down Expand Up @@ -211,3 +211,48 @@ def type_coerce_attrs(self):
self.users = type_coerce_dict(self.users, GdsPermission)
self.groups = type_coerce_dict(self.groups, GdsPermission)
self.roles = type_coerce_dict(self.roles, GdsPermission)


class DataShareInDatasetSummary(RangerBaseModelObject):
def __init__(self, attrs=None):
if attrs is None:
attrs = {}

RangerBaseModelObject.__init__(self, attrs)

self.name = attrs.get('name')
self.serviceId = attrs.get('serviceId')
self.serviceName = attrs.get('serviceName')
self.zoneId = attrs.get('zoneId')
self.zoneName = attrs.get('zoneName')
self.resourceCount = attrs.get('resourceCount')
self.shareStatus = attrs.get('shareStatus')
self.approver = attrs.get('approver')

def type_coerce_attrs(self):
super(DataShareInDatasetSummary, self).type_coerce_attrs()

self.shareStatus = type_coerce(self.shareStatus, GdsShareStatus)


class DatasetSummary(RangerBaseModelObject):
def __init__(self, attrs=None):
if attrs is None:
attrs = {}

RangerBaseModelObject.__init__(self, attrs)

self.name = attrs.get('name')
self.description = attrs.get('description')
self.permissionForCaller = attrs.get('permissionForCaller')
self.principalsCount = attrs.get('principalsCount')
self.projectsCount = attrs.get('projectsCount')
self.totalResourceCount = attrs.get('totalResourceCount')
self.dataShares = attrs.get('dataShares')

def type_coerce_attrs(self):
super(DatasetSummary, self).type_coerce_attrs()

self.permissionForCaller = type_coerce(self.permissionForCaller, GdsPermission)
self.principalsCount = type_coerce_kv(self.principalsCount, PrincipalType, int)
self.dataShares = type_coerce_list(self.dataShares, DataShareInDatasetSummary)
10 changes: 10 additions & 0 deletions intg/src/main/python/apache_ranger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ def type_coerce_list_dict(obj, objType):
return [ type_coerce_dict(entry, objType) for entry in obj ]
return None

def type_coerce_kv(obj, keyType, valType):
if isinstance(obj, dict):
ret = {}
for k, v in obj.items():
ret[type_coerce(k, keyType)] = type_coerce(v, valType)
else:
ret = None

return ret

class API:
def __init__(self, path, method, expected_status, consumes=APPLICATION_JSON, produces=APPLICATION_JSON):
self.path = path
Expand Down

0 comments on commit 789d696

Please sign in to comment.