BigData – My BigDataApi

BigData – My BigDataApi

31 December 2018 0 By Eric Deleforterie

I have updated my python Api for managing Hortonworks Ambari and Ranger with their API.

Here is the GitHub repository https://github.com/EricDele/BigDataApi

Here is an example with the Sandbox to create a policy for HDFS with the Api

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from ambari import AmbariApi
from ranger import RangerApi

if __name__ == '__main__':
  rangerApi = RangerApi("http", "127.0.0.1", "6080", "basic")
  rangerApi.setCredentialsBasic("raj_ops", "raj_ops")

  result = rangerApi.postCreatePolicy(policyTemplateType = "hdfs", serviceName = "Sandbox_hadoop", policyName = "lake_test", 
                                      description = "policy for the lake test",
                                      resources = ["/lake/test","/lake/data"], isRecursive = False, 
                                      users = ["it1"], groups = [], accesses = "r-x")
  print(rangerApi)

The same for creating a Hive policy

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from ambari import AmbariApi
from ranger import RangerApi

if __name__ == '__main__':
    rangerApi = RangerApi("http", "127.0.0.1", "6080", "basic")
    rangerApi.setCredentialsBasic("raj_ops", "raj_ops")
    result = rangerApi.postCreatePolicy(policyTemplateType = "hive", serviceName = "Sandbox_hive", policyName = "hive_test", 
                                        description = "policy for the hive test",
                                        resources = {"column":{"isExcludes":"false","value":["*"]},"table":{"isExcludes":"false","value":["j*","d*"]},"database":{"isExcludes":"false","value":["*"]}}, 
                                        users = ["it1"], groups = [],
                                        accesses = ["select","update","create","drop","alter","index","lock","all","read","write"])
    print(rangerApi)

Feel free to give me feedback.

Please follow and like us: