Is it possible to delete a user from group by restapi

Problem:
With pulp-cli pulp group user remove , I can remove a user from a pulp group

I would like to try by restapi, according to the doc:
https://docs.pulpproject.org/pulpcore/restapi.html#tag/Groups:-Users/operation/groups_users_delete
but I donā€™t know where to get the groups_user_href?
I have :

/pulp/api/v3/groups/4/users/
/pulp/api/v3/groups/
/pulp/api/v3/users/

Does anyone know this?

Thanks in advance


ā€œversionsā€: [
{
ā€œcomponentā€: ā€œcoreā€,
ā€œversionā€: ā€œ3.45.1ā€,
ā€œpackageā€: ā€œpulpcoreā€,
ā€œmoduleā€: ā€œpulpcore.appā€,
ā€œdomain_compatibleā€: true
},
{
ā€œcomponentā€: ā€œrpmā€,
ā€œversionā€: ā€œ3.25.0ā€,
ā€œpackageā€: ā€œpulp-rpmā€,
ā€œmoduleā€: ā€œpulp_rpm.appā€,
ā€œdomain_compatibleā€: true
},

pulp-cli 0.23.2

pulp-cli 0.23.2
pulp-glue 0.23.2

Well, this is Fun! After some investigation, the group_user_href is constructed as ā€œthe part of the user-href after the API ROOT appended to the group-hrefā€.

Example: user ā€˜testuserā€™ is in group ā€˜test-groupā€™

$ pulp group show --name test-group | jq -r '.pulp_href'
/pulp/api/v3/groups/1/
$ pulp user show --username testuser | jq -r '.pulp_href'
/pulp/api/v3/users/2/
$ pulp group user list --group test-group
[
  {
    "username": "testuser",
    "pulp_href": "/pulp/api/v3/users/2/"
  }
]

To delete that user from that group, you need to create the group-user-href by hand to be

/pulp/api/v3/groups/1/users/2/

which isā€¦kind of suboptimal.

You can see pulp-cli doing this work here : https://github.com/pulp/pulp-cli/blob/main/pulpcore/cli/core/group.py#L198

This could prob use an RFE to provide a means of getting the group-user-hrefs for a group from the API. It would be great if you could open one here!

2 Likes

Hello @ggainey , Thanks very much for the example!
Sorry my late reply. I have tested it, it works!
About the RFE( ?), I will do it late. :slight_smile:

1 Like

I think the confusion stems from the fact that the REST api provides access to the group-user which is in fact the join model. So to add a user to a group, you create a join object, and to remove it again, you delete that association again. (Not saying that this was a good designā€¦)

So your RFE would be an add_user and a remove_user http verb?

Hadnā€™t thought it through as far as implementation - just as far as ā€œrequiring as input an HREF that the API doesnā€™t ever show anywhere is Rudeā€ :slight_smile:

Adding new verbs would definitely work. My initial thought, though, was just ā€œimprove the usergroup serializer to show the usergroup_href listā€ - so one could query the group, and then use those HREFs directly in the delete-from-group call.

THe desired-end-state, regardless of how we implement it, is ā€œa user can remove a pulp-user from a group in a way that doesnā€™t require building HREFs by hand.ā€

1 Like

after reading your further explanation, i am not sure if my demand is suitable or not, because maybe some usecase needs user_href when doing groups:users/list users query

I was guessing the groups_user_href must be a a kind of combination of group+user href, but was not sure how, so I put my question :slight_smile:

Your requirement is perfectly valid, and your assumption was perfectly correct - removing a user-from-a-group requires a ā€œhybridā€ of the group-href and the user-href. But itā€™s unreasonable for the API to expect the caller to know how to correctly build such an HREF - there has to be some way for you to query pulp to get the list-of-group/user-hrefs in order to pass them to the remove-from-group API, and currently we donā€™t have such a thing.

after know how, to construct it is not difficult, so I can do it, anyway, I put a REF here :slight_smile:

3 Likes

Well, one of the key goals of REST is, clients have enough information in the resource representation to modify or delete the resource if they want to. This absence violates that expectation - very rude :slight_smile:

Thanks for the RFE - future users will thank you for it! :slight_smile:

1 Like