Feature: Take some of the parameters from the Environment so that it can work in a containerized environment

This commit is contained in:
Tanshu 2016-01-31 13:58:15 +05:30
parent 4b795a6f5d
commit 33b14b1ec0
4 changed files with 70 additions and 8 deletions

View File

@ -1,6 +1,8 @@
import datetime
import os
from pyramid.config import Configurator
from sqlalchemy import engine_from_config
from sqlalchemy.engine.url import make_url
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
@ -10,16 +12,23 @@ from brewman.models import initialize_sql
from brewman.renderers import json_renderer, CSVRenderer
from brewman.security import groupfinder
current_table = 1
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
if 'sqlalchemy.url' not in settings:
DB_NAME = os.environ['DB_NAME']
DB_USER = os.environ['DB_USER']
DB_PASS = os.environ['DB_PASS']
DB_URI = 'postgresql://{0}:{1}@postgres:5432/{2}'.format(
DB_USER, DB_PASS, DB_NAME
)
settings['sqlalchemy.url']= DB_URI
engine = engine_from_config(settings, 'sqlalchemy.')
initialize_sql(engine)
session_factory = SignedCookieSessionFactory('secret')
SECRET_KEY = os.environ.get('SECRET_KEY', settings.get('secret_key', ''))
session_factory = SignedCookieSessionFactory(SECRET_KEY)
authentication_policy = AuthTktAuthenticationPolicy('brewman', timeout=900, reissue_time=90, callback=groupfinder)
authorization_policy = ACLAuthorizationPolicy()

50
container.ini Normal file
View File

@ -0,0 +1,50 @@
[app:main]
use = egg:brewman
pyramid.reload_templates = false
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
secret_key = secret
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 80
# Begin logging configuration
[loggers]
keys = root, brewman, sqlalchemy.engine.base
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARNING
handlers = console
[logger_brewman]
level = WARNING
handlers =
qualname = brewman
[logger_sqlalchemy.engine.base]
level = DEBUG
handlers =
qualname = sqlalchemy.engine.base
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
# End logging configuration

View File

@ -1,5 +1,7 @@
pyramid
pyramid<1.6
waitress
transaction
zope.sqlalchemy
SQLAlchemy
psycopg2

View File

@ -11,9 +11,10 @@ with open(os.path.join(here, 'CHANGES.txt')) as f:
requires = [
'pyramid',
'waitress',
'transaction',
'zope.sqlalchemy',
'SQLAlchemy',
'transaction',
'zope.sqlalchemy',
'SQLAlchemy',
'psycopg2',
]
setup(name='brewman',