Override roster url
This commit is contained in:
parent
8d1f4f3fd8
commit
5c00e9c3ae
2 changed files with 10 additions and 9 deletions
|
@ -25,11 +25,12 @@ The re2o section defines parameter to connect to re2o api.
|
|||
### Mailman section
|
||||
|
||||
| Parameter | Description | Default value |
|
||||
|------------|--------------------------|------------------|
|
||||
|--------------|-------------------------------------------|----------------------------------------------------------------------------------------------------|
|
||||
| `url` | url for mailman api | `localhost:8001` |
|
||||
| `username` | username for mailman api | `restadmin` |
|
||||
| `password` | password for mailman api | `restpassword` |
|
||||
| `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
|
||||
|
||||
|
|
|
@ -13,14 +13,14 @@ mailman_url = config.get('Mailman', 'url')
|
|||
mailman_username = config.get('Mailman', 'username')
|
||||
mailman_password = config.get('Mailman', 'password')
|
||||
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())
|
||||
|
||||
if changed:
|
||||
for section in config.sections():
|
||||
if section not in ["Re2o", "Mailman"] and config.getboolean(section, 'activate'):
|
||||
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():
|
||||
entries = response1.json()['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]
|
||||
if emails_to_delete:
|
||||
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))
|
||||
else:
|
||||
print("[INFO] No member to delete for list {}".format(list_name))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue