VMware Cloud Community
jonathanvh
Enthusiast
Enthusiast
Jump to solution

Permissions of folder

Hi,

I have a vmFolder object in orchestrator.

But I want to get a list of permissions of this folder.

So the User/Group and the Role it has assigned.

Is there an easy way to do this?

Kind regards,

Jonathan

0 Kudos
1 Solution

Accepted Solutions
Jalapeno420
Enthusiast
Enthusiast
Jump to solution

This will give you the User/Group and Role directly on the specific folder.  Unfortunatly, it does not give permissions that may have propagated down from a parent.  If I get time I may modifiy it to do that unless someone beats me to it.

roles = folder.sdkConnection.authorizationManager.roleList;

for (p in folder.permission) {

  System.log(folder.permission[p].principal);

  for (r in roles) {

  if (folder.permission[p].roleId == roles[r].roleId) {

  System.log(roles[r].name);

  }

  }

}

View solution in original post

0 Kudos
4 Replies
Jalapeno420
Enthusiast
Enthusiast
Jump to solution

This will give you the User/Group and Role directly on the specific folder.  Unfortunatly, it does not give permissions that may have propagated down from a parent.  If I get time I may modifiy it to do that unless someone beats me to it.

roles = folder.sdkConnection.authorizationManager.roleList;

for (p in folder.permission) {

  System.log(folder.permission[p].principal);

  for (r in roles) {

  if (folder.permission[p].roleId == roles[r].roleId) {

  System.log(roles[r].name);

  }

  }

}

0 Kudos
jonathanvh
Enthusiast
Enthusiast
Jump to solution

Nice! This is what I was looking for!

If you got the time to do this this would be really helpful.

0 Kudos
Jalapeno420
Enthusiast
Enthusiast
Jump to solution

Give this a try.

roles = folder.sdkConnection.authorizationManager.roleList;

effectivePermissions = new Array();

//Get the folder permissions

for (p in folder.permission) {

  for (r in roles) {

  if (folder.permission[p].roleId == roles[r].roleId) {

  System.log(folder.permission[p].principal + " = " + roles[r].name + " from " + folder.name);

  effectivePermissions.push(folder.permission[p].principal)

  }

  }

}

//Get parent permissions that propagate down

folder = folder.parent;

while (folder) {

  for (p in folder.permission) {

  //if the permissions propagate and were not overriden at a lower level

  if ((folder.permission[p].propagate == true) && (effectivePermissions.indexOf(folder.permission[p].principal) < 0)) {

  for (r in roles) {

  if (folder.permission[p].roleId == roles[r].roleId) {

  System.log(folder.permission[p].principal + " = " + roles[r].name + " from " + folder.name);

  effectivePermissions.push(folder.permission[p].principal)

  }

  }

  }

  }

  folder = folder.parent;

}

jonathanvh
Enthusiast
Enthusiast
Jump to solution

Thanks for the scripts!

They are really useful!

0 Kudos