From 392a51b858dde0c68ce93a9415c3841062a70805 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Thu, 21 Jul 2016 18:16:16 +0300 Subject: Add API token config parameter for API authentication --- project/botmanager.py | 3 ++- project/shoutboxapicommunicator.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'project') diff --git a/project/botmanager.py b/project/botmanager.py index 151e94d..1a3e037 100644 --- a/project/botmanager.py +++ b/project/botmanager.py @@ -37,11 +37,12 @@ class BotManager(object): logging.error("Error creating bot listener. src will now exit...") sys.exit(1) - def set_parameters(self, shoutbox_api_url, telegram_chat_id, api_call_interval): + def set_parameters(self, shoutbox_api_url, telegram_chat_id, api_call_interval, api_auth_token): """Store parameters in the manager instance""" ShoutboxCommunicator.url = shoutbox_api_url TelegramCommunicator.chat_id = telegram_chat_id ShoutboxCommunicator.interval = api_call_interval + ShoutboxCommunicator.token = api_auth_token def start(self): """Try fetching bot information from Telegram to check connection""" diff --git a/project/shoutboxapicommunicator.py b/project/shoutboxapicommunicator.py index c30b408..21e7e8e 100644 --- a/project/shoutboxapicommunicator.py +++ b/project/shoutboxapicommunicator.py @@ -11,6 +11,7 @@ class ShoutboxCommunicator(BaseCommunicator): url = "http://localhost:8000" interval = 10 + token = "" @staticmethod def get_url(): @@ -47,8 +48,9 @@ class ShoutboxCommunicator(BaseCommunicator): @staticmethod def send(data): """Send a message to the API""" - post_params = "?user={}&text={}&id={}&ip={}×tamp={}".format( - data["user"], data["text"], data["id"], data["ip"], data["timestamp"] + post_params = "?user={}&text={}&id={}&ip={}×tamp={}&api_token={}".format( + data["user"], data["text"], data["id"], data["ip"], data["timestamp"], + ShoutboxCommunicator.token ) try: -- cgit v1.3