Skip to content

Instantly share code, notes, and snippets.

@gquere
Last active December 1, 2023 13:47
Show Gist options
  • Save gquere/347e8e042490be87e6e9e32e428cb47a to your computer and use it in GitHub Desktop.
Save gquere/347e8e042490be87e6e9e32e428cb47a 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