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 <chris.obbard@collabora.com>
pull/31/head
Christopher Obbard 2023-01-13 18:09:33 +00:00
parent 1312474e53
commit f47e974c7c
1 changed files with 3 additions and 3 deletions

View File

@ -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 <YOUR_API_KEY>'\n")
"\n\nNo API key set. Run Autodoist with '-a <YOUR_API_KEY>' 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(