def find_entity(request): response = {'status': -1} api = NavigatorApi() entity_type = json.loads(request.POST.get('type', '')) if not entity_type: raise MetadataApiException("find_entity requires a type value, e.g. - 'database', 'table', 'file'") if entity_type.lower() == 'database': name = json.loads(request.POST.get('name', '')) if not name: raise MetadataApiException('get_database requires name param') response['entity'] = api.get_database(name) elif entity_type.lower() == 'table': database = json.loads(request.POST.get('database', '')) name = request.POST.get('name', '') if not database or not name: raise MetadataApiException('get_table requires database and name param') response['entity'] = api.get_table(database, name) elif entity_type.lower() == 'directory': path = json.loads(request.POST.get('path', '')) if not path: raise MetadataApiException('get_directory requires path param') response['entity'] = api.get_directory(path) elif entity_type.lower() == 'file': path = json.loads(request.POST.get('path', '')) if not path: raise MetadataApiException('get_file requires path param') response['entity'] = api.get_file(path) else: raise MetadataApiException("type %s is unrecognized" % entity_type) response['status'] = 0 return JsonResponse(response)
def get_entity(request): response = {'status': -1} api = NavigatorApi() entity_id = request.REQUEST.get('id') if not entity_id: raise MetadataApiException("get_entity requires an 'id' parameter") response['entity'] = api.get_entity(entity_id) response['status'] = 0 return JsonResponse(response)
def delete_properties(request): response = {'status': -1} api = NavigatorApi() entity_id = json.loads(request.POST.get('id', '')) keys = json.loads(request.POST.get('keys', [])) if not entity_id or not keys or not isinstance(keys, list): response['error'] = _("update_properties requires an 'id' parameter and 'keys' parameter that is a non-empty list") else: response['entity'] = api.delete_properties(entity_id, keys) response['status'] = 0 return JsonResponse(response)
def update_properties(request): response = {'status': -1} api = NavigatorApi() entity_id = json.loads(request.POST.get('id', '')) properties = json.loads(request.POST.get('properties', {})) if not entity_id or not properties or not isinstance(properties, dict): response['error'] = _("update_properties requires an 'id' parameter and 'properties' parameter that is a non-empty dict") else: response['entity'] = api.update_properties(entity_id, properties) response['status'] = 0 return JsonResponse(response)
def delete_tags(request): response = {'status': -1} api = NavigatorApi() entity_id = json.loads(request.POST.get('id', '')) tags = json.loads(request.POST.get('tags', [])) if not entity_id or not tags or not isinstance(tags, list): response['error'] = _("add_tags requires an 'id' parameter and 'tags' parameter that is a non-empty list of tags") else: response['entity'] = api.delete_tags(entity_id, tags) response['status'] = 0 return JsonResponse(response)
def delete_properties(request): response = {'status': -1} api = NavigatorApi() entity_id = json.loads(request.POST.get('id', '')) keys = json.loads(request.POST.get('keys', [])) if not entity_id or not keys or not isinstance(keys, list): response['error'] = _( "update_properties requires an 'id' parameter and 'keys' parameter that is a non-empty list" ) else: response['entity'] = api.delete_properties(entity_id, keys) response['status'] = 0 return JsonResponse(response)
def update_properties(request): response = {'status': -1} api = NavigatorApi() entity_id = json.loads(request.POST.get('id', '')) properties = json.loads(request.POST.get('properties', {})) if not entity_id or not properties or not isinstance(properties, dict): response['error'] = _( "update_properties requires an 'id' parameter and 'properties' parameter that is a non-empty dict" ) else: response['entity'] = api.update_properties(entity_id, properties) response['status'] = 0 return JsonResponse(response)
def delete_tags(request): response = {'status': -1} api = NavigatorApi() entity_id = json.loads(request.POST.get('id', '')) tags = json.loads(request.POST.get('tags', [])) if not entity_id or not tags or not isinstance(tags, list): response['error'] = _( "add_tags requires an 'id' parameter and 'tags' parameter that is a non-empty list of tags" ) else: response['entity'] = api.delete_tags(entity_id, tags) response['status'] = 0 return JsonResponse(response)
def setup_class(cls): if not is_live_cluster() or not cls.is_navigator_enabled(): raise SkipTest cls.client = make_logged_in_client(username='******', is_superuser=False) cls.user = User.objects.get(username='******') add_to_group('test') grant_access("test", "test", "metadata") grant_access("test", "test", "navigator") cls.api = NavigatorApi()
def find_entity(request): response = {'status': -1} api = NavigatorApi() entity_type = json.loads(request.POST.get('type', '')) if not entity_type: raise MetadataApiException( "find_entity requires a type value, e.g. - 'database', 'table', 'file'" ) if entity_type.lower() == 'database': name = json.loads(request.POST.get('name', '')) if not name: raise MetadataApiException('get_database requires name param') response['entity'] = api.get_database(name) elif entity_type.lower() == 'table': database = json.loads(request.POST.get('database', '')) name = request.POST.get('name', '') if not database or not name: raise MetadataApiException( 'get_table requires database and name param') response['entity'] = api.get_table(database, name) elif entity_type.lower() == 'directory': path = json.loads(request.POST.get('path', '')) if not path: raise MetadataApiException('get_directory requires path param') response['entity'] = api.get_directory(path) elif entity_type.lower() == 'file': path = json.loads(request.POST.get('path', '')) if not path: raise MetadataApiException('get_file requires path param') response['entity'] = api.get_file(path) else: raise MetadataApiException("type %s is unrecognized" % entity_type) response['status'] = 0 return JsonResponse(response)