proper config management

This commit is contained in:
codl 2017-07-26 11:11:54 +02:00
parent 912674c3f4
commit e7cfb44321
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
4 changed files with 57 additions and 7 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/config.py
__pycache__

14
app.py
View File

@ -4,11 +4,17 @@ from sqlalchemy import MetaData
from flask_migrate import Migrate
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///forget'
app.config['SQLALCHEMY_ECHO'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.secret_key = 'hunter2'
default_config = {
"SQLALCHEMY_ECHO": True,
"SQLALCHEMY_TRACK_MODIFICATIONS": False,
"SQLALCHEMY_DATABASE_URI": "postgresql+psycopg2:///forget",
"SECRET_KEY": "hunter2"
}
app.config.update(default_config)
app.config.from_pyfile('config.py', True)
metadata = MetaData(naming_convention = {
"ix": 'ix_%(column_0_label)s',

41
config.example.py Normal file
View File

@ -0,0 +1,41 @@
"""
this is an example config file for Forget
copy this file to config.py before editing
"""
"""
DATABASE URI
determines where to connect to the database
see http://docs.sqlalchemy.org/en/latest/core/engines.html#database-urls for syntax
only postgresql with psycopg2 driver is officially supported
"""
SQLALCHEMY_DATABASE_URI='postgresql+psycopg2:///forget'
"""
SECRET KEY
this key is used to encrypt session cookies
you can generate a random key by running
openssl rand -base64 102 | tr -d "\n"; echo
or if you don't have openssl installed
cat /dev/random | head -c 102 | base64 | tr -d "\n"; echo
the latter might take a while if your system entropy is low, give it time
"""
SECRET_KEY='change me!'
"""
TWITTER CREDENTIALS
get these at apps.twitter.com
blah
"""
TWITTER_CONSUMER_KEY='vdsvdsvds'
TWITTER_CONSUMER_SECRET='hjklhjklhjkl'
"""
you can also use any config variable that flask expects here, such as
"""
# SESSION_COOKIE_SECURE=True
# DEBUG=True

View File

@ -1,6 +1,6 @@
{% if session %}
Hello, {{session['display_name']}}! <a href="/logout">Log out</a>
<code>{{session['created_at']}}</code>
<p>Hello, {{session['display_name']}}! <a href="/logout">Log out</a></p>
<p><code>{{session}}</code></p>
{% else %}
Hello, stranger! <a href="/login/twitter">Log in with Twitter</a>
<p>Hello, stranger! <a href="/login/twitter">Log in with Twitter</a></p>
{% endif %}