Search code examples
artifactory

Automating removing user groups


I'm trying to automate removing the users groups in Artifactory for users who leave the company. I'm retrieving their user JSON details, then modifying the JSON by deleting the groups section. So far so good. But when I upload the updated JSON the groups are not removed from that user in Artifactory. I'm using the following command to upload the updated JSON:

curl -u <username>:<password> -XPUT "<server name>/artifactory/api/security/users/<user>" -H "Content-Type: application/json" -T user.json

I'm not getting an error when executing the command, but nothing is updated for that user. Any ideas what I'm doing wrong here?


Solution

  • As per the Artifactory REST API wiki you should use a POST method to update a User's groups, so as an example - To update a user (u1) and delete his groups I would use:

    curl -u<an_admin_user>:<a_password> -XPOST http://<rt_server>:<port>/artifactory/api/security/users/u1 -T /path/to/file/Update_U1_Groups.json
    

    where the JSON file would look like:

    {
     "name" : "u1",
     "groups" : []
    }