Override roster url
This commit is contained in:
parent
8d1f4f3fd8
commit
5c00e9c3ae
2 changed files with 10 additions and 9 deletions
13
README.md
13
README.md
|
@ -24,12 +24,13 @@ The re2o section defines parameter to connect to re2o api.
|
||||||
|
|
||||||
### Mailman section
|
### Mailman section
|
||||||
|
|
||||||
| Parameter | Description | Default value |
|
| Parameter | Description | Default value |
|
||||||
|------------|--------------------------|------------------|
|
|--------------|-------------------------------------------|----------------------------------------------------------------------------------------------------|
|
||||||
| `url` | url for mailman api | `localhost:8001` |
|
| `url` | url for mailman api | `localhost:8001` |
|
||||||
| `username` | username for mailman api | `restadmin` |
|
| `username` | username for mailman api | `restadmin` |
|
||||||
| `password` | password for mailman api | `restpassword` |
|
| `password` | password for mailman api | `restpassword` |
|
||||||
| `domain` | domain for mailing lists | `example.net` |
|
| `domain` | domain for mailing lists | `example.net` |
|
||||||
|
| `roster_url` | roster url for getting and deleting email | None (`http://{mailman_url}/3.1/lists/{list_name}@{domain}/roster/member` will be used by default) |
|
||||||
|
|
||||||
### Sections for mailing-lists
|
### Sections for mailing-lists
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@ mailman_url = config.get('Mailman', 'url')
|
||||||
mailman_username = config.get('Mailman', 'username')
|
mailman_username = config.get('Mailman', 'username')
|
||||||
mailman_password = config.get('Mailman', 'password')
|
mailman_password = config.get('Mailman', 'password')
|
||||||
domain = config.get('Mailman', 'domain')
|
domain = config.get('Mailman', 'domain')
|
||||||
|
roster_url = config.get('Mailman', 'roster_url', fallback='http://{mailman_url}/3.1/lists/{list_name}@{domain}/roster/member')
|
||||||
changed = int(open(filename).read())
|
changed = int(open(filename).read())
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
for section in config.sections():
|
for section in config.sections():
|
||||||
if section not in ["Re2o", "Mailman"] and config.getboolean(section, 'activate'):
|
if section not in ["Re2o", "Mailman"] and config.getboolean(section, 'activate'):
|
||||||
list_name = config.get(section, "list_name", fallback=section)
|
list_name = config.get(section, "list_name", fallback=section)
|
||||||
response1 = requests.get('http://{}/3.1/lists/{}@{}/roster/member'.format(mailman_url, list_name, domain), auth=(mailman_username, mailman_password))
|
response1 = requests.get(roster_url.format(mailman_url=mailman_url, list_namelist_name, domain=domain), auth=(mailman_username, mailman_password))
|
||||||
if "entries" in response1.json():
|
if "entries" in response1.json():
|
||||||
entries = response1.json()['entries']
|
entries = response1.json()['entries']
|
||||||
old_emails = [entry['email'] for entry in entries]
|
old_emails = [entry['email'] for entry in entries]
|
||||||
|
@ -28,7 +28,7 @@ if changed:
|
||||||
emails_to_delete = [email for email in old_emails if email not in new_emails]
|
emails_to_delete = [email for email in old_emails if email not in new_emails]
|
||||||
if emails_to_delete:
|
if emails_to_delete:
|
||||||
print("[..] Deleting non members from list {}".format(list_name))
|
print("[..] Deleting non members from list {}".format(list_name))
|
||||||
response = requests.delete('http://{}/3.1/lists/{}@{}/roster/member'.format(mailman_url, list_name, domain), auth=(mailman_username,mailman_password), params={'emails': emails_to_delete})
|
response = requests.delete(roster_url.format(mailman_url=mailman_url, list_name=list_name, domain=domain), auth=(mailman_username,mailman_password), params={'emails': emails_to_delete})
|
||||||
print("[OK] Non members where deleted from list {}".format(list_name))
|
print("[OK] Non members where deleted from list {}".format(list_name))
|
||||||
else:
|
else:
|
||||||
print("[INFO] No member to delete for list {}".format(list_name))
|
print("[INFO] No member to delete for list {}".format(list_name))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue