Compare commits
3 Commits
fcd0089240
...
303ddc002c
Author | SHA1 | Date | |
---|---|---|---|
303ddc002c | |||
f87cfbb435 | |||
8897651285 |
@ -5,6 +5,7 @@ Update Mailman 2 lists via a json API of the form {"LIST": ["ADDRESS", ...]}
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
@ -34,11 +35,12 @@ def sync_members(
|
|||||||
capture_output=True,
|
capture_output=True,
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
print(output.stdout)
|
for line in output.stdout.splitlines():
|
||||||
|
print(f"[Syncing {mailing_list}] {line}")
|
||||||
|
|
||||||
|
|
||||||
def main(mailman_bin: Path, api: str, token: str, list_suffix: str, dry_run: bool):
|
def main(mailman_bin: Path, api: str, api_auth: str, list_suffix: str, dry_run: bool):
|
||||||
r = requests.get(api, headers={"Authorization": "Token " + token})
|
r = requests.get(api, headers={"Authorization": api_auth})
|
||||||
if not r.ok:
|
if not r.ok:
|
||||||
print(f"Failed to get mailing list data from api: {r.status_code} {r.text}")
|
print(f"Failed to get mailing list data from api: {r.status_code} {r.text}")
|
||||||
return
|
return
|
||||||
@ -67,7 +69,6 @@ if __name__ == "__main__":
|
|||||||
help="Path to Mailman site admin scripts (default %(default)s)",
|
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("--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("--list-suffix", help="Suffix for mailing lists")
|
||||||
argp.add_argument(
|
argp.add_argument(
|
||||||
"-n",
|
"-n",
|
||||||
@ -77,8 +78,14 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
args = argp.parse_args()
|
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:
|
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:
|
except subprocess.CalledProcessError as e:
|
||||||
print(e.stderr)
|
print(e.stderr)
|
||||||
raise
|
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