2017-04-13 12:29:56 -04:00
|
|
|
#!/usr/bin/python -tt
|
|
|
|
|
|
|
|
"""
|
|
|
|
This script is ran as a cronjob and bastion.
|
|
|
|
|
|
|
|
Its goal is to generate all the <pkg>-owner email aliases we provide
|
|
|
|
"""
|
|
|
|
|
2020-05-07 18:49:29 +02:00
|
|
|
import time
|
|
|
|
|
2017-04-13 12:29:56 -04:00
|
|
|
import requests
|
|
|
|
|
2017-08-09 17:48:43 +00:00
|
|
|
from requests.adapters import HTTPAdapter
|
|
|
|
from requests.packages.urllib3.util.retry import Retry
|
|
|
|
|
|
|
|
|
|
|
|
def retry_session():
|
|
|
|
session = requests.Session()
|
|
|
|
retry = Retry(
|
|
|
|
total=5,
|
|
|
|
read=5,
|
|
|
|
connect=5,
|
|
|
|
backoff_factor=0.3,
|
|
|
|
status_forcelist=(500, 502, 504),
|
|
|
|
)
|
|
|
|
adapter = HTTPAdapter(max_retries=retry)
|
|
|
|
session.mount('http://', adapter)
|
|
|
|
session.mount('https://', adapter)
|
|
|
|
return session
|
|
|
|
|
|
|
|
|
2017-08-04 20:36:39 +00:00
|
|
|
pagure_url = 'https://src.fedoraproject.org/'
|
2017-04-13 12:29:56 -04:00
|
|
|
pagure_group_url = pagure_url + '/api/0/group/{group}'
|
|
|
|
project_to_email = {}
|
|
|
|
|
2017-08-04 20:37:26 +00:00
|
|
|
|
|
|
|
def get_pagure_projects():
|
2017-10-15 17:03:09 +00:00
|
|
|
pagure_projects_url = pagure_url + '/api/0/projects?page=1&per_page=100&fork=false'
|
2017-08-09 17:48:43 +00:00
|
|
|
session = retry_session()
|
2017-08-04 20:37:26 +00:00
|
|
|
while pagure_projects_url:
|
2020-05-07 18:49:29 +02:00
|
|
|
cnt = 0
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
response = session.get(pagure_projects_url)
|
|
|
|
data = response.json()
|
|
|
|
break
|
|
|
|
except Exception:
|
|
|
|
if cnt == 4:
|
|
|
|
raise
|
|
|
|
|
|
|
|
cnt += 1
|
|
|
|
time.sleep(30)
|
|
|
|
|
2017-08-04 20:37:26 +00:00
|
|
|
for project in data['projects']:
|
|
|
|
yield project
|
|
|
|
# This is set to None on the last page.
|
|
|
|
pagure_projects_url = data['pagination']['next']
|
|
|
|
|
|
|
|
|
2017-08-09 17:48:43 +00:00
|
|
|
session = retry_session()
|
2017-12-02 22:13:13 +00:00
|
|
|
group_data = {}
|
2017-08-04 20:37:26 +00:00
|
|
|
for project in get_pagure_projects():
|
2017-04-13 12:29:56 -04:00
|
|
|
users = set(project['access_users']['owner']) | \
|
|
|
|
set(project['access_users']['admin']) | \
|
|
|
|
set(project['access_users']['commit'])
|
|
|
|
groups = set()
|
|
|
|
for group_kind in ('admin', 'commit'):
|
|
|
|
for group in project['access_groups'][group_kind]:
|
|
|
|
groups.add(group)
|
|
|
|
|
|
|
|
for group in groups:
|
2017-12-02 22:13:13 +00:00
|
|
|
if group in group_data:
|
|
|
|
users = users | group_data[group]
|
|
|
|
continue
|
2020-05-11 13:43:04 +02:00
|
|
|
|
|
|
|
cnt = 0
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
response = session.get(pagure_group_url.format(group=group))
|
|
|
|
data = response.json()
|
|
|
|
break
|
|
|
|
except Exception:
|
|
|
|
if cnt == 4:
|
|
|
|
raise
|
|
|
|
cnt += 1
|
|
|
|
time.sleep(30)
|
|
|
|
|
|
|
|
group_members = data['members']
|
2017-04-13 12:29:56 -04:00
|
|
|
users = users | set(group_members)
|
2017-12-02 22:13:13 +00:00
|
|
|
group_data[group] = set(group_members)
|
2017-04-13 12:29:56 -04:00
|
|
|
|
2017-04-13 16:25:46 -04:00
|
|
|
project_alias = '{0}-owner'.format(project['name'])
|
|
|
|
# If there is a namespace, prefix the email with it plus a dash
|
|
|
|
if project['namespace'] and project['namespace'] != 'rpms':
|
|
|
|
project_alias = '{0}-{1}'.format(project['namespace'], project_alias)
|
|
|
|
|
2017-04-13 12:29:56 -04:00
|
|
|
# Use the @fedoraproject.org email alias instead of looking their email up
|
|
|
|
# in FAS
|
2017-08-09 17:46:11 +00:00
|
|
|
emails = ['{0}@fedoraproject.org'.format(user) for user in users]
|
|
|
|
|
|
|
|
# Handle case-insensitivity in postfix by unioning things.
|
|
|
|
project_alias = project_alias.lower()
|
|
|
|
if project_alias in project_to_email:
|
|
|
|
project_to_email[project_alias] = project_to_email[project_alias].union(emails)
|
|
|
|
else:
|
|
|
|
project_to_email[project_alias] = set(emails)
|
|
|
|
|
2017-04-13 12:29:56 -04:00
|
|
|
|
2017-04-13 16:25:46 -04:00
|
|
|
for project_alias, emails in project_to_email.items():
|
|
|
|
print('{0}: {1}'.format(project_alias, ','.join(sorted(emails))))
|