diff --git a/inventory/host_vars/mailman01.phx2.fedoraproject.org b/inventory/host_vars/mailman01.phx2.fedoraproject.org index 37f7ac8707..d87bd0feb0 100644 --- a/inventory/host_vars/mailman01.phx2.fedoraproject.org +++ b/inventory/host_vars/mailman01.phx2.fedoraproject.org @@ -11,6 +11,6 @@ datacenter: phx2 lvm_size: 750000 # GDPR SAR variables -sar_script: /srv/webui/bin/hyperkitty-sar.py +sar_script: /srv/webui/bin/mailman-sar.py sar_script_user: apache sar_output_file: mailinglists.json diff --git a/roles/mailman/files/hyperkitty-sar.py b/roles/mailman/files/mailman-sar.py similarity index 55% rename from roles/mailman/files/hyperkitty-sar.py rename to roles/mailman/files/mailman-sar.py index 8bc058b2d4..980b6dcfcd 100644 --- a/roles/mailman/files/hyperkitty-sar.py +++ b/roles/mailman/files/mailman-sar.py @@ -20,6 +20,8 @@ from six.moves.urllib.parse import urljoin ENV_EMAIL = "SAR_EMAIL" HYPERKITTY_INSTANCE = "http://localhost/archives/" +MAILMAN_INSTANCE = "http://localhost:8001/" +MAILMAN_AUTH = ("restadmin", "restpass") log = logging.getLogger() @@ -52,6 +54,41 @@ def get_emails(address): return emails +def get_subscriptions(address): + url = urljoin(MAILMAN_INSTANCE, + "3.1/members/find?subscriber={}".format(address)) + response = requests.get(url, auth=MAILMAN_AUTH) + if response.status_code >= 300: + log.error("Could not get URL %s: %d %s", + url, response.status_code, response.reason) + return [] + result = response.json() + subscriptions = [] + for entry in result.get("entries", []): + subscription = { + "list_id": entry["list_id"], + "role": entry["role"], + "delivery_mode": entry["delivery_mode"], + } + # Get the subscription's preferences + member_id = entry["member_id"] + pref_url = urljoin(MAILMAN_INSTANCE, + "3.1/members/{}/preferences".format(member_id)) + pref_response = requests.get(pref_url, auth=MAILMAN_AUTH) + pref_result = pref_response.json() + if pref_response.status_code >= 300: + log.error("Could not get URL %s: %d %s", + pref_url, pref_response.status_code, + pref_response.reason) + else: + subscription["preferences"] = dict([ + (key, pref_result[key]) for key in pref_result + if key not in ("http_etag", "self_link") + ]) + subscriptions.append(subscription) + return subscriptions + + def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--debug", action="store_true") @@ -70,8 +107,10 @@ def main(): stream=sys.stderr, ) emails = get_emails(email) + subscriptions = get_subscriptions(email) print(json.dumps(dict( - emails=emails, count=len(emails), + emails=emails, + subscriptions=subscriptions, ), indent=2)) diff --git a/roles/mailman/tasks/main.yml b/roles/mailman/tasks/main.yml index e2c3c2427d..bf00f953fb 100644 --- a/roles/mailman/tasks/main.yml +++ b/roles/mailman/tasks/main.yml @@ -440,7 +440,7 @@ - post-update.sh - import-mm2.py - periodic.py - - hyperkitty-sar.py + - mailman-sar.py - name: install the templatized scripts template: src={{ item }}.j2 dest="{{ mailman_webui_basedir }}/bin/{{ item }}"