Skip to content

Instantly share code, notes, and snippets.

@maen08
Forked from gquere/artifactory_list_users.py
Created February 7, 2023 15:22
Show Gist options
  • Save maen08/75989e82b57bd8e320b65890e8525b8b to your computer and use it in GitHub Desktop.
Save maen08/75989e82b57bd8e320b65890e8525b8b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import requests
import json
import urllib3
import sys
# SUPPRESS WARNINGS ############################################################
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# ADD USER #####################################################################
def check_users(details):
global users
if 'createdBy' not in details:
return
if details['createdBy'] not in users:
print('Found user {}'.format(details['createdBy']))
users.append(details['createdBy'])
if details['modifiedBy'] not in users:
print('Found user {}'.format(details['modifiedBy']))
users.append(details['modifiedBy'])
# MAIN #########################################################################
url = sys.argv[1].rstrip('/')
session = requests.Session()
response = session.get(url + '/api/repositories', verify=False)
repositories = json.loads(response.text)
users = []
print('There are {} repositories to process'.format(len(repositories)))
for repository in repositories:
try:
response = session.get(url + '/api/storage/' + repository['key'], verify=False)
if 'json' not in response.headers['Content-Type']:
continue
rep = json.loads(response.text)
for child in rep['children']:
uri = child['uri']
response = session.get(url + '/api/storage/' + repository['key'] + uri, verify=False)
if 'json' not in response.headers['Content-Type']:
continue
details = json.loads(response.text)
check_users(details)
except Exception as e:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment