UMIACS / rgwadmin

Ceph Object Storage Admin API python library bindings.
https://rgwadmin.readthedocs.io/
GNU Lesser General Public License v2.1
85 stars 47 forks source link

create_user throws RGWAdminException instead of UserExists #66

Closed vergeev closed 1 year ago

vergeev commented 1 year ago

Steps to reproduce:

from rgwadmin import RGWAdmin

rgw = RGWAdmin(access_key='XXX', secret_key='XXX', server='obj.example.com')
rgw.create_user(
    uid='liam',
    display_name='Liam Monahan',
    email='liam@umiacs.umd.edu',
    user_caps='usage=read, write; users=read',
    max_buckets=1000)
rgw.create_user(
    uid='liam',
    display_name='Liam Monahan',
    email='liam@umiacs.umd.edu',
    user_caps='usage=read, write; users=read',
    max_buckets=1000)

Expected result: the last line throws rgwadmin.exceptions.UserExists.

Actual result: the last line throws rgwadmin.exceptions.RGWAdminException with code="UserAlreadyExists".

Why I think this is happening: the docs say the error response is UserExists, but the rgw code actually produces UserAlreadyExists.

Solution I propose:

  1. Add UserAlreadyExists exception, replace with it UserExists here: https://github.com/UMIACS/rgwadmin/blob/4f90b6a53d680abd441f52606c2317719d2fe06d/rgwadmin/rgw.py#L131
  2. Make UserExists an alias of UserAlreadyExists in order to maintain backwards compatibility.

Can I go ahead and open a pull request with a fix?

dyarnell commented 1 year ago

Hi Pavel,

I think this is reasonable. The UserAlreadyExists goes back at least to the 12.x.x version of Ceph as the exception in the code. Please provide a pull request and I will be happy to merge.

vergeev commented 1 year ago

Here's the PR: https://github.com/UMIACS/rgwadmin/pull/67. Please let me know if you want me to add anything.

dyarnell commented 1 year ago

This was released as part of https://github.com/UMIACS/rgwadmin/releases/tag/2.4.4 and is available on PyPI now.