From 69b735b9cb69b570c3c176e501d392b3d1728525 Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 28 Jan 2021 17:13:37 -0500 Subject: [PATCH] Change to load keys from environment variable --- README.rst | 10 ++++++---- cfwatch.py | 20 +++++++++++++++++--- setup.py | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index a900002..d9dc42e 100644 --- a/README.rst +++ b/README.rst @@ -17,14 +17,11 @@ Usage $ pip install cfwatch $ cfwatch --help - usage: cfwatch.py [-h] [-l LOG] email token zone prefix [dir] + usage: cfwatch.py [-h] [-l LOG] zone prefix [dir] Purges CloudFlare on local file change. positional arguments: - email CloudFlare login email (e.g. user@example.com) - token CloudFlare API key (e.g. - c2547eb745079dac9320b638f5e225cf483cc5cfdda41) zone CloudFlare zone (e.g. example.com) prefix CloudFlare path prefix (e.g. http://example.com/) dir directory to watch, i.e. file.txt this directory is @@ -34,5 +31,10 @@ Usage -h, --help show this help message and exit -l LOG, --log LOG log file +When running ``cfwatch``, you must set the following environment variables: + +* ``CFWATCH_EMAIL`` to your CloudFlare login email (e.g. user@example.com) +* ``CFWATCH_TOKEN`` to your CloudFlare API key + .. |pypi| image:: https://img.shields.io/pypi/v/cfwatch.svg :target: https://pypi.python.org/pypi/cfwatch diff --git a/cfwatch.py b/cfwatch.py index 3bd0809..973b592 100755 --- a/cfwatch.py +++ b/cfwatch.py @@ -1,6 +1,9 @@ #!/usr/bin/env python +from __future__ import print_function + import logging import os +import sys from threading import Lock, Event, Thread try: @@ -138,8 +141,6 @@ def main(): import argparse parser = argparse.ArgumentParser(description='Purges CloudFlare on local file change.') - parser.add_argument('email', help='CloudFlare login email (e.g. user@example.com)') - parser.add_argument('token', help='CloudFlare API key (e.g. c2547eb745079dac9320b638f5e225cf483cc5cfdda41)') parser.add_argument('zone', help='CloudFlare zone (e.g. example.com)') parser.add_argument('prefix', help='CloudFlare path prefix (e.g. http://example.com/)') parser.add_argument('dir', nargs='?', default='.', @@ -151,7 +152,20 @@ def main(): logging.basicConfig(filename=args.log, format='%(asctime)-15s %(message)s', level=logging.INFO) - monitor = CloudFlareMonitorHandler(args.email, args.token, args.zone, args.prefix, args.dir) + email = os.environ.get('CFWATCH_EMAIL') + token = os.environ.get('CFWATCH_TOKEN') + + if not email: + print('CFWATCH_EMAIL environment variable must be set to CloudFlare login email ' + '(e.g. user@example.com)', file=sys.stderr) + sys.exit(2) + + if not token: + print('CFWATCH_TOKEN environment must set to CloudFlare API key ' + '(e.g. c2547eb745079dac9320b638f5e225cf483cc5cfdda41)', file=sys.stderr) + sys.exit(2) + + monitor = CloudFlareMonitorHandler(email, token, args.zone, args.prefix, args.dir) monitor.run() diff --git a/setup.py b/setup.py index de0a3da..4bda945 100755 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as f: setup( name='cfwatch', - version='0.1.0', + version='0.2.0', description="Automagically purges CloudFlare's cache when local files are updated.", long_description=readme, author='Quantum',