Jfrog API to add users to group incrementally without replacing

230 views Asked by At

We are trying to automate JFrog access management using Azuredevops tasks and couldn't find any working solution to update the user addition to the groups in an update passion without replacing existing users from the list. We are looking for CLI commands or API calls for below scenario.

  1. How we can ensure specific user exists in system,

  2. adding a existing user to specific group in incremental way. That means, each time when we need to add a user to group, it should add the user to the group without changing any property or already existing users in it.

1

There are 1 answers

5
yinon On

Both requirements should be possible via the JFrog Platform REST API.

  1. Check a user exists - Use the get user API -

    GET /access/api/v2/users/{username}
    

    Check the response status code - 200 exists, 404 not found.

  2. Add a user to a group as a member -
    There are two ways to do that -

    1. Update the user -
      PATCH /access/api/v2/{username}/groups
      
      {
        "add": [ "group1" ],
        "remove": [ "group2" ]
      }
      
    2. Update the group -
      PATCH /access/api/v2/groups/{name}/members
      
      {
        "add": [ "user1", "user2" ],
        "remove": [ "user1", "user2" ]
      }