Skip to content

Commit 7e8d459

Browse files
author
Anze
committed
Allow bot token to be specified via BOT_TOKEN_FROM_FILE
1 parent bec3678 commit 7e8d459

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pingcollector.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,15 @@ def do_ping(*args, **job_info):
8888

8989
backend_url = os.environ.get('BACKEND_URL')
9090
bot_token = os.environ.get('BOT_TOKEN')
91+
if not bot_token:
92+
# bot token can also be specified via contents of a file:
93+
bot_token_from_file = os.environ.get('BOT_TOKEN_FROM_FILE')
94+
if bot_token_from_file:
95+
with open(bot_token_from_file, 'rt') as f:
96+
bot_token = f.read()
97+
9198
if not backend_url or not bot_token:
92-
raise Exception("Please specify BACKEND_URL and BOT_TOKEN env vars.")
99+
raise Exception("Please specify BACKEND_URL and BOT_TOKEN / BOT_TOKEN_FROM_FILE env vars.")
93100
jobs_refresh_interval = int(os.environ.get('JOBS_REFRESH_INTERVAL', 120))
94101

95102
c = PingCollector(backend_url, bot_token, jobs_refresh_interval)

0 commit comments

Comments
 (0)