Compare commits
3 Commits
303ddc002c
...
fcd0089240
Author | SHA1 | Date | |
---|---|---|---|
fcd0089240 | |||
dbce4f278a | |||
d9a4a2c665 |
@ -5,6 +5,7 @@ Update Mailman 2 lists via a json API of the form {"LIST": ["ADDRESS", ...]}
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
@ -34,11 +35,12 @@ def sync_members(
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
print(output.stdout)
|
||||
for line in output.stdout.splitlines():
|
||||
print(f"{mailing_list}: {line}")
|
||||
|
||||
|
||||
def main(mailman_bin: Path, api: str, token: str, list_suffix: str, dry_run: bool):
|
||||
r = requests.get(api, headers={"Authorization": "Token " + token})
|
||||
def main(mailman_bin: Path, api: str, api_auth: str, list_suffix: str, dry_run: bool):
|
||||
r = requests.get(api, headers={"Authorization": api_auth})
|
||||
if not r.ok:
|
||||
print(f"Failed to get mailing list data from api: {r.status_code} {r.text}")
|
||||
return
|
||||
@ -67,7 +69,6 @@ if __name__ == "__main__":
|
||||
help="Path to Mailman site admin scripts (default %(default)s)",
|
||||
)
|
||||
argp.add_argument("--api", required=True, help="API endpoint to retrieve JSON from")
|
||||
argp.add_argument("--token", required=True, help="Authorization Token for API")
|
||||
argp.add_argument("--list-suffix", help="Suffix for mailing lists")
|
||||
argp.add_argument(
|
||||
"-n",
|
||||
@ -77,8 +78,14 @@ if __name__ == "__main__":
|
||||
)
|
||||
args = argp.parse_args()
|
||||
|
||||
if "API_AUTH" in os.environ:
|
||||
api_auth = os.environ.get('API_AUTH')
|
||||
else:
|
||||
print("Missing API_AUTH environment variable")
|
||||
exit(-1)
|
||||
|
||||
try:
|
||||
main(args.bin, args.api, args.token, args.list_suffix, args.dry_run)
|
||||
main(args.bin, args.api, api_auth, args.list_suffix, args.dry_run)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(e.stderr)
|
||||
raise
|
||||
|
13
systemd/mailman_sync.service
Normal file
13
systemd/mailman_sync.service
Normal file
@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=Synchronize Mailman lists to CMSManage API
|
||||
|
||||
[Service]
|
||||
User=mailman
|
||||
Group=mailman
|
||||
Type=oneshot
|
||||
TimeoutStartSec=600
|
||||
EnvironmentFile=/opt/mailman-sync/env
|
||||
ExecStart=/usr/bin/python3.9 /opt/mailman-sync/mailman_sync.py \
|
||||
--bin /usr/local/cpanel/3rdparty/mailman/bin/ \
|
||||
--api https://paperwork.claremontmakerspace.org/api/v1/paperwork/certification_definition/mailing_lists.json \
|
||||
--list-suffix _claremontmakerspace.org
|
9
systemd/mailman_sync.timer
Normal file
9
systemd/mailman_sync.timer
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Periodically synchronize Mailman lists to CMSManage API
|
||||
|
||||
[Timer]
|
||||
OnCalendar=hourly
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
Loading…
Reference in New Issue
Block a user