#2011 Fix mailman-sar script
Merged 11 months ago by zlopez. Opened a year ago by lenkaseg.
fedora-infra/ lenkaseg/ansible mailman  into  main

@@ -6,46 +6,38 @@ 

  standard output.

  """

  

- from __future__ import absolute_import, unicode_literals, print_function

- 

  import argparse

  import json

  import logging

  import os

  import sys

  

+ from configparser import ConfigParser

  import requests

- from six.moves.urllib.parse import urljoin

  

+ config = ConfigParser()

+ config.read("/etc/mailman.cfg")

+ username = config.get("webservice", "admin_user")

+ userpass = config.get("webservice", "admin_pass")

  

  ENV_EMAIL = "SAR_EMAIL"

  HYPERKITTY_INSTANCE = "http://localhost/archives/"

  MAILMAN_INSTANCE = "http://localhost:8001/"

- MAILMAN_AUTH = ("restadmin", "restpass")

+ MAILMAN_AUTH = (username, userpass)

  

  log = logging.getLogger()

  

  

  def get_emails(address):

      url = urljoin(HYPERKITTY_INSTANCE, "api/sender/{}/emails/".format(address))

-     result = {"next": url}

-     count = None

      email_urls = []

-     while result.get("next"):

-         url = result["next"]

-         response = requests.get(url)

-         if response.status_code >= 300:

-             log.error("Could not get URL %s: %d %s",

-                       url, response.status_code, response.reason)

-             break

-         result = response.json()

-         if count is None:

-             count = result["count"]

-         email_urls.extend([e["url"] for e in result["results"]])

-     if count != len(email_urls):

-         log.error("Mismatch in the number of emails: got %s but there are "

-                   "%s in total.", len(email_urls), count)

-         raise ValueError

+     response = requests.get(url)

+     if response.status_code >= 300:

+         log.error("Could not get URL %s: %d %s",

+                   url, response.status_code, response.reason)

+         raise ConnectionError

+     result = response.json()

+     email_urls.extend([e["url"] for e in result])

      emails = []

      for url in email_urls:

          response = requests.get(url)

Removed some python2 syntax.
Related to https://pagure.io/fedora-infrastructure/issue/8455

rebased onto ad60848454b5bbd8a687d482428c7a06ad284ba5

11 months ago

Removed pagination from get_emails function.

Not ready yet, I have to add the mailman authentication.

@lenkaseg I found out I pointed you to wrong script for reading the mailman config. You should look here instead https://pagure.io/fedora-infra/ansible/blob/main/f/roles/mailman3/files/migrate_fedora_auth.py

rebased onto 14c37e9

11 months ago

Works on staging.
Ready for review.

Looks good, let me merge it

Pull-Request has been merged by zlopez

11 months ago

@lenkaseg I found out I pointed you to wrong script for reading the mailman config. You should look here instead https://pagure.io/fedora-infra/ansible/blob/main/f/roles/mailman3/files/migrate_fedora_auth.py

Somehow I didn't notice this message yesterday. Checking the migrate_fedora_auth.py, it is done a little different. Do you want me to rewrite it?

No need if it's working as it is now.

Metadata