Reputation: 2102
We have our company users list and with that users list we need to prepare a report that each user have access to which gerrit project.
So how to list the project(s) for particular user from gerrit?
Some direction to achieve this will be helpful. Thanks in advance.
Upvotes: 0
Views: 1213
Reputation: 22351
You have two options to give a try:
Using the "--has-acl-for GROUP" option, you can list projects on which access rights for this group are directly assigned. Note: projects which only inherit access rights for this group are not listed:
ssh -p 29418 USER@GERRIT-SERVER gerrit ls-projects --has-acl-for GROUP
See more details in Gerrit documentation here.
Using this endpoint you can verify if a user has access to a repository. Note: this requires the View Access global capability:
curl --user USER:PASS --request GET "https://GERRIT-SERVER/a/projects/PROJECT/check.access?account=ACCOUNT-ID&ref=refs%2Fheads%2Fmaster"
This command checks if the user with the ACCOUNT-ID number has access to the branch "master" of the PROJECT. As you have noted, you need to know the user ACCOUNT-ID. You can find the user ACCOUNT-ID using REST too:
curl --user USER:PASS --request GET "https://GERRIT-SERVER/a/accounts/?q=username:USERNAME" | sed 1d | jq --raw-output .[]._account_id
See more details in Gerrit documentation here.
Upvotes: 1