diff --git a/mailman_sync.py b/mailman_sync.py index 44623ed..c599f90 100755 --- a/mailman_sync.py +++ b/mailman_sync.py @@ -16,11 +16,11 @@ Update Mailman 3 lists via a json API of the form: } """ -import argparse import json import os import email.utils +import configargparse import mailmanclient import requests @@ -207,8 +207,13 @@ def main( def parse_arguments(): - argp = argparse.ArgumentParser(description=__doc__) + argp = configargparse.ArgumentParser(description=__doc__) + argp.add("-c", "--config", is_config_file=True, help="Config file path") + argp.add_argument("--api", required=True, help="API endpoint to retrieve JSON from") + argp.add_argument( + "--api-auth", required=True, help="API Authorization header token" + ) argp.add_argument("--mail-host", help="Base domain for all lists", required=True) argp.add_argument( @@ -219,6 +224,9 @@ def parse_arguments(): argp.add_argument( "--mailman-user", help="Username for Mailman3 REST API", default="restadmin" ) + argp.add_argument( + "--mailman-pass", help="Password for Mailman3 REST API", required=True + ) argp.add_argument( "--cf-auth-token", help="Auth token for CloudFlare API", required=True @@ -249,20 +257,15 @@ def parse_arguments(): if __name__ == "__main__": args = parse_arguments() - for env_var in ("API_AUTH", "MAILMAN_PASS"): - if env_var not in os.environ: - print(f"Missing {env_var} environment variable") - exit(-1) - mailman_client = mailmanclient.Client( args.mailman_url + "/3.1", args.mailman_user, - os.environ["MAILMAN_PASS"], + args.mailman_pass, ) main( args.api, - os.environ["API_AUTH"], + args.api_auth, mailman_client, args.dry_run, args.mail_host, diff --git a/systemd/mailman_sync.service b/systemd/mailman_sync.service index f578668..b6dc642 100644 --- a/systemd/mailman_sync.service +++ b/systemd/mailman_sync.service @@ -6,9 +6,4 @@ User=mailman Group=mailman Type=oneshot TimeoutStartSec=600 -EnvironmentFile=/opt/mailman-sync/env -ExecStart=/usr/bin/python3 /opt/mailman-sync/mailman_sync.py \ - --api https://paperwork.claremontmakerspace.org/api/v1/paperwork/department/mailing_lists.json \ - --mail-host claremontmakerspace.org \ - --mailman-url http://localhost:8001 \ - --mailman-user restadmin +ExecStart=/usr/bin/python3 /opt/mailman-sync/mailman_sync.py --config /opt/mailman-sync/config.yml