indigo-iam/iam

Unable to retrieve complete list of users or groups using the Indigo IAM API

Closed this issue · 4 comments

sigau commented

Hi ,

I'm currently facing an issue while utilizing the Indigo IAM API to manage various aspects. When attempting to fetch the complete list of users or groups from our IAM instance, I'm only receiving the first 10 entries. I've been using the following commands:

Command to fetch groups:
curl -s -H "Authorization: Bearer $AT" http://ccosfip00284.in2p3.fr:/iam/group/search | jq

Command to fetch users:
curl -s -H "Authorization: Bearer ${AT}" http://ccosfip00284.in2p3.fr:/iam/account/search | jq

I've tried appending ?limit=100 or ?per_page=100 to the API endpoint, but unfortunately, it doesn't yield the desired result.

Is there a way to retrieve the full list of users or groups using the provided command?

Thanks in advance,
Gautier

Hi, this is a paginated view of users when the itemsPerPage is set to 10.

To check the complete list of users please increment startIndex by 10, such as

https://wlcg.cloud.cnaf.infn.it/iam/account/search?startIndex=11
sigau commented

hi,

Thank you for your response.
Is it possible to include all the group or user information in a single command?
Currently, we use a script that parses the JSON file obtained from the command and performs certain actions on our server side (like create a account for some indigoIAM users for one or multiple specific tools based on their group on indigo IAM) . Having one JSON file containing all the necessary data would make it easier for us (like all the user or all the group) , especially when dealing with multiple users (e.g., 200 users represent 20 json files), as we wouldn't have to manually concatenate individual files because to parse the json file everything should be in the "Resources": [...] part .

Thank you for your attention to this matter.

Hi,

you can write a simple script to put all accounts/groups in a single JSON file or use the SCIM API which is not paginated (doc. https://indigo-iam.github.io/v/v1.8.2/docs/reference/api/scim-api/#get-scimusers).

Example script:

import requests, json
token = 'XXX'

headers = {"Authorization": "Bearer %s" % token}

results = []
startIndex = 1
totalResults = Y  # total number of users
itemsPerPage = 10
while(startIndex < totalResults):
    list_url = "https://<your-iam-instance>/iam/account/search?startIndex=%d" % startIndex
    resp = requests.get(list_url, headers=headers)
    data = resp.json()
    startIndex += itemsPerPage
    for user in data['Resources']:
        results.append(user)
with open('accounts.json', 'w+') as fp:
    fp.write(json.dumps(results))
sigau commented

Thank you that exactly what I was trying to do !
thank you very much @rmiccoli and @federicaagostini