aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan-sebastian.tuomi@aalto.fi>2016-07-21 18:16:16 +0300
committerJan Tuomi <jan-sebastian.tuomi@aalto.fi>2016-07-21 18:16:16 +0300
commit392a51b858dde0c68ce93a9415c3841062a70805 (patch)
tree2553cd5c34091ec15b5fa57e815c2a250ee2de51
parente13ae89fcbd1543bf583e7a56f82ccaef4dfa8d4 (diff)
Add API token config parameter for API authentication
-rw-r--r--bot.config3
-rw-r--r--project/botmanager.py3
-rw-r--r--project/shoutboxapicommunicator.py6
-rwxr-xr-xradiodiodibot3
4 files changed, 10 insertions, 5 deletions
diff --git a/bot.config b/bot.config
index 72593d0..0a89799 100644
--- a/bot.config
+++ b/bot.config
@@ -1,5 +1,6 @@
[GENERAL]
-TelegramBotToken=208028818:AAFAeLDGsjp5vFi_ljdciuTODzRPufldeZo
+TelegramBotToken=
ShoutboxApiUrl=http://127.0.0.1:8000
TelegramChatID=123
ApiCallInterval=5
+ApiAuthToken=
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={}&timestamp={}".format(
- data["user"], data["text"], data["id"], data["ip"], data["timestamp"]
+ post_params = "?user={}&text={}&id={}&ip={}&timestamp={}&api_token={}".format(
+ data["user"], data["text"], data["id"], data["ip"], data["timestamp"],
+ ShoutboxCommunicator.token
)
try:
diff --git a/radiodiodibot b/radiodiodibot
index 2cfc3dd..f23b9f7 100755
--- a/radiodiodibot
+++ b/radiodiodibot
@@ -66,6 +66,7 @@ def main():
shoutbox_api_url = config["GENERAL"]["ShoutboxApiUrl"]
telegram_chat_id = config["GENERAL"]["TelegramChatID"]
api_call_interval = int(config["GENERAL"]["ApiCallInterval"])
+ api_auth_token = config["GENERAL"]["ApiAuthToken"]
# If the user has specified the parameters as command line
# arguments, use them to override the config values
@@ -83,7 +84,7 @@ def main():
# Store the final values in a manager instance
manager = botmanager.BotManager(telegram_bot_token)
- manager.set_parameters(shoutbox_api_url, telegram_chat_id, api_call_interval)
+ manager.set_parameters(shoutbox_api_url, telegram_chat_id, api_call_interval, api_auth_token)
logging.info("Using Shoutbox API URL: {}".format(shoutbox_api_url))
logging.info("Using Telegram Chat ID: {}".format(telegram_chat_id))