Support Questions
Find answers, ask questions, and share your expertise

Rest api for amabri views

Rest api for amabri views

I want to add group into ambari views for e.g hive views or file views . Is there rest api available adding group into the particular view ?

3 REPLIES 3

Re: Rest api for amabri views

Hi @Anurag Mishra

With the REST API you can only LIST/GET permissions for VIEWS with the REST API

https://github.com/apache/ambari/blob/trunk/ambari-server/docs/api/v1/permission-resources.md

PermissionInfo/resource_nameThe resource type this permission is related to. Possible values include:
AMBARI - the Ambari server, itself
CLUSTER - a cluster managed by the Ambari server VIEW - a view managed by the Ambari server Update an existing permission resource. This operation is not supported, permissions are read-only resources. Create a new permission resource. This operation is not supported, permissions are read-only resources.

Re: Rest api for amabri views

@Anurag Mishra

You can try following API

HiveInstance1 - instance name
group1 - Group name
curl 'http://172.25.37.139:8080/api/v1/views/HIVE/versions/2.0.0/instances/HiveInstance1/privileges' -X PUT  -H "X-Requested-By: ambari"
 --data-binary '[{"PrivilegeInfo":{"permission_name":"VIEW.USER","principal_name":"group1","principal_type":"GROUP"}}]' --compressed

Re: Rest api for amabri views

Contributor

Hi @Anurag Mishra

To manage Ambari View permissions and give access to any user or groups, you can use below api call

/api/v1/views/$VIEW_TYPE/versions/$VIEW_VERSION/instances/$VIEW_INSTANCE/privileges 

With Payload

{
  "PrivilegeInfo": {
    "permission_name": "VIEW.USER",
    "principal_name": "username",
    "principal_type": "USER"
  }
}
{
  "PrivilegeInfo": {
    "permission_name": "VIEW.USER",
    "principal_name": "groupname",
    "principal_type": "GROUP"
  }
}

In below example I providing access to user1, user2, group1 & group2 to Hive View

curl -u admin:<AMBARI_ADMIN_PASSWORD> -H "X-Requested-By: ambari" \
-X PUT -d \
'{"PrivilegeInfo": {"permission_name": "VIEW.USER","principal_name": "group1","principal_type": "GROUP"}},{"PrivilegeInfo": {"permission_name": "VIEW.USER","principal_name": "group2","principal_type": "GROUP"}},{"PrivilegeInfo": {"permission_name": "VIEW.USER","principal_name": "user1","principal_type": "USER"}},{"PrivilegeInfo": {"permission_name": "VIEW.USER","principal_name": "user2","principal_type": "USER"}}' \
http://<AMBARI_HOSTNAME>:8080/api/v1/views/$VIEW_TYPE/versions/$VIEW_VERSION/instances/$VIEW_INSTANC...

Notes:

Modify below values accordingly

VIEW_TYPE (in the API URL) to the relevant view type (i.e. FILES,HIVE etc)

VIEW_VERSION (in the API URL) to the relevant view type (i.e. 1.5.1, 2.0.0 etc,)

VIEW_INSTANCE (in the API URL) to the relevant view type (i.e. AUTO_FILES_INSTANCE, AUTO_HIVE_INSTANCE, MyFileView etc)

principal_type (in the payload) value to the relevant type (i.e. USER, GROUP)

principal_name (in the payload) value to the relevant username and Group name (ex, user1, user2, group1, group2 etc)