1. Copy the below script to a .py extension file (in ours e.g it is set as file.py)
2. Open the file in an editor and change the bearer token(inputvalueforbearertoken) based on the access token you are generating in your Artifactory instance. The “artinstanceurl” needs to be replaced with your Artifactory URL. Also please change searchrealm variable too based on the realm you are searching for.
3. Once you are done with the previous 2 steps, please go to the location of the file in a command or terminal window and use the following command “python3 file.py”.
import requests import json token = 'inputvalueforbearertoken' headers = {'Content-type': 'application/json', 'Authorization': 'Bearer ' + token} url = "https://artinstanceurl/artifactory/api/security/users" y = requests.get(url, headers=headers) searchrealm = 'internal' data = json.loads(y.text) dataout = [] index = 0 for user in data: if searchrealm == user["realm"]: dataout.insert(index, user) index += 1 jsonString = json.dumps(dataout) print(jsonString) print("The number of users with the realm " + "'"+searchrealm+"'" + " were " + str(index))
2. Open the file in an editor and change the bearer token(inputvalueforbearertoken) based on the access token you are generating in your Artifactory instance. The “artinstanceurl” needs to be replaced with your Artifactory URL. Also please change searchrealm variable too based on the realm you are searching for.
3. Once you are done with the previous 2 steps, please go to the location of the file in a command or terminal window and use the following command “python3 file.py”.