From 7e8d459276157a773b264002c8fa3f903efbb2e8 Mon Sep 17 00:00:00 2001 From: Anze Date: Sat, 7 Dec 2019 13:01:20 +0100 Subject: [PATCH] Allow bot token to be specified via BOT_TOKEN_FROM_FILE --- pingcollector.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pingcollector.py b/pingcollector.py index 7dee43b..58ec5c7 100644 --- a/pingcollector.py +++ b/pingcollector.py @@ -88,8 +88,15 @@ def do_ping(*args, **job_info): backend_url = os.environ.get('BACKEND_URL') bot_token = os.environ.get('BOT_TOKEN') + if not bot_token: + # bot token can also be specified via contents of a file: + bot_token_from_file = os.environ.get('BOT_TOKEN_FROM_FILE') + if bot_token_from_file: + with open(bot_token_from_file, 'rt') as f: + bot_token = f.read() + if not backend_url or not bot_token: - raise Exception("Please specify BACKEND_URL and BOT_TOKEN env vars.") + raise Exception("Please specify BACKEND_URL and BOT_TOKEN / BOT_TOKEN_FROM_FILE env vars.") jobs_refresh_interval = int(os.environ.get('JOBS_REFRESH_INTERVAL', 120)) c = PingCollector(backend_url, bot_token, jobs_refresh_interval)