Пример #1
0
def main(global_config, **settings):
    config = Configurator(settings=settings)
    auth_token = MozillaTokenLibForHeaderAuthenticationPolicy(secret='what_makes_so_secret', hashmod=hashlib.sha256, timeout=86400)
    auth_permission = ACLAuthorizationPolicy()
    config.set_authentication_policy(auth_token)
    config.set_authorization_policy(auth_permission)

    client = MongoReplicaSetClient(host=settings['mongodb.host'], replicaSet=settings['mongodb.set'])
    config.registry.settings['mongodb.db'] = client[settings['mongodb.name']]
    upyun_server = UpYun(settings['upyun.space'], settings['upyun.username'], settings['upyun.password'], timeout=30, endpoint=ED_AUTO)
    config.registry.settings['UpYun.server'] = upyun_server
    config.registry.settings['UpYun.debug'] = settings['upyun.debug']
    config.add_subscriber(add_couchdb_to_request, NewRequest)
    DEFAULT_FILTERS.pop()
    config.include("cornice")
    config.scan("api.views.v_0_1_0")
    return config.make_wsgi_app()
Пример #2
0

def exception_filter(response, request):
    """
    Log exceptions that get thrown up to cornice.

    Args:
        response (object): The response returned by a request handler.
        request (pyramid.request.Request): The current web request.
    """
    if isinstance(response, Exception):
        log.exception('Unhandled exception raised:  %r' % response)
    return response


DEFAULT_FILTERS.insert(0, exception_filter)

#
# Bodhi initialization
#

#: An SQLAlchemy scoped session with an engine configured using the settings in Bodhi's server
#: configuration file. Note that you *must* call :func:`initialize_db` before you can use this.
Session = scoped_session(sessionmaker())


def initialize_db(config):
    """
    Initialize the database using the given configuration.

    This *must* be called before you can use the :data:`Session` object.
Пример #3
0
def get_releases(request):
    from bodhi.models import Release
    return Release.all_releases(request.db)

#
# Cornice filters
#

def exception_filter(response, request):
    """Log exceptions that get thrown up to cornice"""
    if isinstance(response, Exception):
        log.exception('Unhandled exception raised:  %r' % response)
    return response

from cornice.validators import DEFAULT_FILTERS
DEFAULT_FILTERS.insert(0, exception_filter)


#
# Bodhi initialization
#

def main(global_config, testing=None, session=None, **settings):
    """ This function returns a WSGI application """
    # Setup our buildsystem
    buildsys.setup_buildsystem(settings)

    # Sessions & Caching
    from pyramid.session import SignedCookieSessionFactory
    session_factory = SignedCookieSessionFactory(settings['session.secret'])