Comment 0 for bug 1413146

Revision history for this message
whhw (wanghuan2) wrote : Glance v2 index dose not support 'admin_as_user' parameter

When admin user list images, we add admin_ad_user=False to query images that are owned by the user, shared to the user and other public images, instead of list all the images.
But if I add this to v2 command like:

curl -i -X GET -H 'X-Auth-Token:07abcf7d5a4d4ad6a03570b73d7ab98a' http://172.30.101.153:9292/v2/images?admin_as_user=True

the result will always be empty, like:

{"images": [], "schema": "/v2/schemas/images", "first": "/v2/images?admin_as_user=True"}

It is because the index of v2 inplementation does not accept 'admin_as_user', instead all the other parameters that are not present will be passed into 'filters'.
[glance/api/v2/images.py]
def index(self, req, marker=None, limit=None, sort_key='created_at',
          sort_dir='desc', filters=None, member_status='accepted'):

A simple method to fix is, add this code to image_get_all(), so we can get it from the filters before querying database.
[glance/db/sqlachemy/api.py]:
def image_get_all(context, filters=None, marker=None, limit=None,
                  sort_key='created_at', sort_dir='desc',
                  member_status='accepted', is_public=None,
                  admin_as_user=False, return_tag=False):
......

# added
if 'admin_as_user' in filters:
admin_as_user = filters.pop('admin_as_user')
if admin_as_user.lower() == 'true':
    admin_as_user = True
else:
    admin_as_user = False