From f47e974c7cf2c1f1b035144610f53bef02e19aa0 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Fri, 13 Jan 2023 18:09:33 +0000 Subject: [PATCH] Allow setting Todoist API key from environment variable In the Docker world, secrets (e.g. passwords, API keys) are usually shared with an application as environment variables so that they can be imported from separate secure areas: in docker-compose you can specify a file where secrets are imported from as environment variables. Read the API key from the TODOIST_API_KEY environment variable first, then check the command-line argument. Signed-off-by: Christopher Obbard --- autodoist.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autodoist.py b/autodoist.py index 941574f..09e4539 100644 --- a/autodoist.py +++ b/autodoist.py @@ -333,7 +333,7 @@ def initialise_api(args): # Check we have a API key if not args.api_key: logging.error( - "\n\nNo API key set. Run Autodoist with '-a '\n") + "\n\nNo API key set. Run Autodoist with '-a ' or set the environment variable TODOIST_API_KEY.\n") sys.exit(1) # Check if alternative end of day is used @@ -1356,8 +1356,8 @@ def main(): # Main process functions. parser = argparse.ArgumentParser( formatter_class=make_wide(argparse.HelpFormatter, w=120, h=60)) - parser.add_argument('-a', '--api_key', - help='takes your Todoist API Key.', type=str) + parser.add_argument( + '-a', '--api_key', help='takes your Todoist API Key.', default=os.environ.get('TODOIST_API_KEY'), type=str) parser.add_argument( '-l', '--label', help='enable next action labelling. Define which label to use.', type=str) parser.add_argument(