From: Tom Hunger Date: Sun, 1 Mar 2015 17:04:41 +0000 (+0000) Subject: Allow setting twitter consumer secret and key through the environment. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=4027805f977b4869c321c0002727a8485b6f7f17;p=sirius.git Allow setting twitter consumer secret and key through the environment. This is done in a backwards-compatible way using the hard-coded key for now so I can add a better error message when the env vars are missing. --- diff --git a/README.md b/README.md index 62fe42c..6e2461f 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,24 @@ $ bin/gunicorn -k flask_sockets.worker sirius.server:app -b 0.0.0.0:5002 -w 1 Navigate browser to http://127.0.0.1:5002/ +## Environment variables + +The server can be configured with the following variables: + +``` +TWITTER_CONSUMER_KEY=... +TWITTER_CONSUMER_SECRET=... +FLASK_CONFIG=... +``` + +For dokku this means using e.g.: + +``` +dokku config:set sirius FLASK_CONFIG=heroku +dokku config:set sirius TWITTER_CONSUMER_KEY=DdrpQ1uqKuQouwbCsC6OMA4oF +dokku config:set sirius TWITTER_CONSUMER_SECRET=S8XGuhptJ8QIJVmSuIk7k8wv3ULUfMiCh9x1b19PmKSsBh1VDM +``` + ## Creating fake printers and friends Resetting the actual hardware all the time gets a bit tiresome so diff --git a/sirius/web/twitter.py b/sirius/web/twitter.py index af0eacd..379dac3 100644 --- a/sirius/web/twitter.py +++ b/sirius/web/twitter.py @@ -1,5 +1,6 @@ from __future__ import absolute_import +import os import datetime import flask from gevent import pool @@ -23,8 +24,8 @@ twitter = oauth_app.remote_app( request_token_url='https://api.twitter.com/oauth/request_token', access_token_url='https://api.twitter.com/oauth/access_token', authorize_url='https://api.twitter.com/oauth/authenticate', - consumer_key='DdrpQ1uqKuQouwbCsC6OMA4oF', - consumer_secret='S8XGuhptJ8QIJVmSuIk7k8wv3ULUfMiCh9x1b19PmKSsBh1VDM', + consumer_key=os.environ.get('TWITTER_CONSUMER_KEY', 'DdrpQ1uqKuQouwbCsC6OMA4oF'), + consumer_secret=os.environ.get('TWITTER_CONSUMER_SECRET', 'S8XGuhptJ8QIJVmSuIk7k8wv3ULUfMiCh9x1b19PmKSsBh1VDM'), )