Operators need to assign User roles after creating a user in TAS (Tanzu Application Service) and might want to know the number of assigned roles for a specific user.
How to efficiently calculate the total number of assigned roles for a specific user?
1. Retrieve the GUID for the selected user.
$ cf curl /v3/users | jq '.resources[] | select(.username=="<USER-NAME>")' | jq '.guid'
"SOME-GUID"
2. Get the total number of assigned roles for the selected user.
$ cf curl /v3/roles | jq '.resources[].relationships.user.data.guid' | grep "<SOME-GUID>" | wc -l
How to quickly retrieve the assigned role names for a specific user?
$ cf curl /v3/roles | jq '.resources[] | select(.relationships.user.data.guid=="<SOME-GUID>")' | jq '.type'
"organization_manager"
"space_manager"
"organization_user"
"space_developer"
"space_auditor"