示例#1
0
def main(global_settings, **settings):
    config = Configurator(
        settings=settings,
        session_factory=SignedCookieSessionFactory('itsaseekreet'))
    config.include('pyramid_jinja2')
    config.add_jinja2_search_path('pyramid_pages_example:templates')
    config.add_static_view('pyramid_pages_example_static', 'static')

    # Database
    settings = config.get_settings()
    settings[CONFIG_SQLALCHEMY_URL] =\
        settings.get(CONFIG_SQLALCHEMY_URL,
                     'sqlite:///example.sqlite')
    engine = engine_from_config(settings)
    DBSession.configure(bind=engine)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    fixture = Fixtures(DBSession)
    fixture.add(WebPage, 'fixtures/pages.json')
    fixture.add(WebPage, 'fixtures/country.json')
    fixture.add(NewsPage, 'fixtures/news.json')
    fixture.add(Gallery, 'fixtures/gallery.json')
    fixture.add(Photo, 'fixtures/photos.json')

    # pyramid_pages
    settings[CONFIG_PYRAMID_PAGES_DBSESSION] =\
        settings.get(CONFIG_PYRAMID_PAGES_DBSESSION,
                     DBSession)
    settings[CONFIG_PYRAMID_PAGES_MODELS] =\
        settings.get(CONFIG_PYRAMID_PAGES_MODELS, models)
    config.include("pyramid_pages")
    config.add_subscriber(add_globals, BeforeRender)
    return config.make_wsgi_app()
示例#2
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings, root_factory=GlobalRootFactory)
    config.include('pyramid_mako')

    # Parse/Convert setting keys that have specifyed datatypes
    for key in config.registry.settings.keys():
        config.registry.settings[key] = convert_str_with_type(config.registry.settings[key])

    # Session Manager
    session_settings = extract_subkeys(config.registry.settings, 'session.')
    session_factory = SignedCookieSessionFactory(serializer=json_serializer, **session_settings)
    config.set_session_factory(session_factory)

    # Routes
    def append_format_pattern(route):
        return re.sub(r'{(.*)}', r'{\1:[^/\.]+}', route) + r'{spacer:[.]?}{format:(%s)?}' % '|'.join(registered_formats())

    config.add_static_view('static', 'static', cache_max_age=3600)

    #config.add_route('home', append_format_pattern('/'))
    config.add_view('gluegov.views.traversal.home', context='gluegov.traversal.TraversalRoot')
    config.add_view('gluegov.views.traversal.group', context='gluegov.traversal.TableGroupResource')
    config.add_view('gluegov.views.traversal.table', context='gluegov.traversal.TableResource')

    config.add_subscriber(add_render_globals_to_template, pyramid.events.BeforeRender)

    config.scan()
    return config.make_wsgi_app()
示例#3
0
def main(global_config, **settings):
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    serializer = JSONSerializerWithPickleFallback()
    session_factory = SignedCookieSessionFactory("qweqweqwe",
                                                 serializer=serializer)

    config = Configurator(settings=settings,
                          root_factory='server.resources.Root')

    config.set_session_factory(session_factory)

    config.include('pyramid_mako')
    config.include('pyramid_tm')

    csrf_policy = LegacySessionCSRFStoragePolicy()
    config.set_csrf_storage_policy(csrf_policy)

    authn_policy = AuthTktAuthenticationPolicy(settings['server.secret'],
                                               callback=groupfinder,
                                               hashalg='sha512')
    authz_policy = ACLAuthorizationPolicy()
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    config.include(admin_include, route_prefix='/')
    config.include(banner_include, route_prefix='/')

    config.add_static_view('static', 'server:static/')
    return config.make_wsgi_app()
示例#4
0
def main(global_config, **settings):
    """ This function returns a WSGI application.
    
    It is usually called by the PasteDeploy framework during 
    ``paster serve``.
    """
    settings = dict(settings)
    settings.setdefault('jinja2.i18n.domain', 'hello_world')

    # Start Sphinx Include 2
    my_session_factory = SignedCookieSessionFactory('itsaseekreet')
    config = Configurator(root_factory=get_root,
                          settings=settings,
                          session_factory=my_session_factory)
    # End Sphinx Include 2
    config.add_translation_dirs('locale/')
    # Start Include
    config.include('pyramid_jinja2')
    # End Include

    config.add_static_view('static', 'static')
    config.add_view('hello_world.views.my_view',
                    context='hello_world.models.MyModel',
                    renderer="mytemplate.jinja2")

    return config.make_wsgi_app()
示例#5
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    NotSoSecret = 'CIeUz0RK8fjRq1wJSrID'
    authn_policy = AuthTktAuthenticationPolicy(NotSoSecret,
                                               callback=groupfinder,
                                               hashalg='sha512')
    authz_policy = ACLAuthorizationPolicy()
    session_factory = SignedCookieSessionFactory(NotSoSecret)

    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(settings=settings, root_factory=Root)
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.include('velruse.providers.google_oauth2')
    config.set_session_factory(session_factory)
    config.add_google_oauth2_login_from_settings(prefix='velruse.google.')
    config.include('cornice')
    config.include('pyramid_mako')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('client_agent', 'client_agent', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('tagged', '/tagged/{tags}')
    config.add_route('users', '/users')
    config.add_route('logout', '/logout')
    config.add_route('redirectme', '/go/{uid}')
    config.add_route('provision', '/provision')
    config.add_route('logs', '/logs/{uuid}')
    config.add_route('wall', '/wall/{tags}')
    config.add_request_method(LookupUser, 'user', reify=True)
    config.scan()
    return config.make_wsgi_app()
示例#6
0
def main():
    """Create a configured wsgi app"""
    settings = {}
    settings['reload_all'] = os.environ.get('DEBUG', True)
    settings['debug_all'] = os.environ.get('DEBUG', True)
    settings['db'] = os.environ.get(
        'DATABASE_URL', 'dbname=learning_journal user=efrain-petercamacho')
    settings['auth.username'] = os.environ.get('AUTH_USERNAME', 'admin')
    manager = BCRYPTPasswordManager()
    settings['auth.password'] = os.environ.get('AUTH_PASSWORD',
                                               manager.encode('secret'))
    secret = os.environ.get('JOURNAL_SESSION_SECRET', 'itsaseekrit')
    session_factory = SignedCookieSessionFactory(secret)
    auth_secret = os.environ.get('JOURNAL_AUTH_SECRET', 'anotherseekrit')
    # configuration setup
    config = Configurator(
        settings=settings,
        session_factory=session_factory,
        authentication_policy=AuthTktAuthenticationPolicy(secret=auth_secret,
                                                          hashalg='sha512'),
        authorization_policy=ACLAuthorizationPolicy(),
    )
    jinja2.filters.FILTERS['markdown'] = markd
    config.include('pyramid_jinja2')
    config.add_static_view('static', os.path.join(here, 'static'))
    config.add_route('home', '/')
    config.add_route('add', '/add')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('details', '/details/{id}')
    config.add_route('editor', '/editor/{id}')
    config.add_route('delete', '/delte/{id}')
    config.scan()
    app = config.make_wsgi_app()
    return app
示例#7
0
def main(settings={
    'SECRET_KEY': 'dev',
    'DATABASE': os.path.join(os.getcwd(), 'igloo.sql'),
}):
    # create and configure the app.
    config = Configurator(settings=settings)

    # set up session.
    session_factory = SignedCookieSessionFactory(
        'secret', serializer=serializer.Serializer())
    config.set_session_factory(session_factory)

    # set up jinja2.
    config.include('pyramid_jinja2')
    config.add_jinja2_search_path('templates/')

    # import routes, views, static, etc.
    config.include(routes)
    config.scan(auth)
    config.scan(blog)
    config.add_static_view(name='static', path='static')

    # set up database.
    db.init_db(config.registry)
    config.add_subscriber(db.connection, NewRequest)
    config.add_request_method(auth.user, 'user')

    app = config.make_wsgi_app()

    return app
示例#8
0
def main(global_config, **settings):
	""" This function returns a Pyramid WSGI application.
	"""
	engine = engine_from_config(settings, 'sqlalchemy.')
	DBSession.configure(bind=engine)
	Base.metadata.bind = engine

	shrt_lkr_session_factory = SignedCookieSessionFactory('SoF4K1n6S3cr3T')

	config = Configurator(settings=settings)
	config.set_session_factory(shrt_lkr_session_factory)
	config.include('pyramid_mako')
	config.add_subscriber(add_referer_globals, BeforeRender)

	config.add_static_view('static', 'static', cache_max_age=3600)
	config.add_route('home', '/')

	config.add_route('link_list', '/admin/link/')
	config.add_route('link_create', '/admin/link/new')
	config.add_route('link_edit', '/admin/link/{id}')
	config.add_route('link_delete', '/admin/link/delete/{id}')

	config.add_route('link_hit', '/{hashids}')


	config.add_static_view('deform_static', 'deform:static/')
	#config.add_static_view('static', 'deform:static')

	config.scan()
	return config.make_wsgi_app()
def main(global_config, **settings):
    with Configurator(settings=settings) as config:
        engine = engine_from_config(settings, "sqlalchemy.")
        DBSession.configure(bind=engine)
        Base.metadata.bind = engine

        config.include("pyramid_jinja2")
        config.include(".routes")
        this_session_factory = SignedCookieSessionFactory("itsaseekreet")

        config = Configurator(settings=settings,
                              root_factory="quotes.models.Root",
                              session_factory=this_session_factory)

        config.registry.dbmaker = sessionmaker(bind=engine)
        config.add_request_method(db, reify=True)

        config.include("pyramid_chameleon")
        config.include("pyramid_jinja2")
        config.include(".routes")

        session_factory = get_session_factory(
            engine_from_config(settings, prefix="sqlalchemy."))
        config.add_request_method(
            lambda request: get_tm_session(session_factory, request.tm),
            "dbsession",
            reify=True)
        config.scan(".views")

    return config.make_wsgi_app()
示例#10
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config_path = global_config['__file__']
    app_info = configparser.ConfigParser()
    app_info.read(config_path)        
    InitSetting(app_info)
    
    config = Configurator(settings=settings)
    
    config.include('pyramid_chameleon')
    config.add_static_view(name='static', path= 'static', cache_max_age=0)  
    config.add_static_view(name='website', path= '../website', cache_max_age=0)
  
    config.add_route('test', '/test')
    config.add_route('home', '/')    
  
    config.add_route('UpdateNews','/UpdateNews')
    config.add_route('ExtractNews','/ExtractNews')   
    
    config.add_route('api','/api/{func}')   
    
    ys_session_factory = SignedCookieSessionFactory("thisissecretkay")
    config.set_session_factory(ys_session_factory)

    config.scan()
    return config.make_wsgi_app()
示例#11
0
def do_config(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    load_project_settings()

    session_factory = SignedCookieSessionFactory(
        settings.get('session.secret', 'hello'))

    config = Configurator(session_factory=session_factory, settings=settings)
    config.add_renderer('prettyjson', JSON(indent=4))
    config.include('pyramid_mako')
    config.add_view('pyramid.view.append_slash_notfound_view',
                    context='pyramid.httpexceptions.HTTPNotFound')

    # ArangoDB configuration
    graph_models.connect(server=settings['gdb.server'],
                         port=settings['gdb.port'],
                         username=settings['gdb.username'],
                         password=settings['gdb.password'],
                         db_name=settings['gdb.database'])

    application_routes(config)
    config.scan()

    return config
示例#12
0
def main(global_config, **settings):
    """Application factory"""
    config = Configurator(settings=settings, root_factory=RootFactory)
    declare_routes(config)

    session_factory = SignedCookieSessionFactory(
        settings.get('session_key', 'itsaseekreet'))
    config.set_session_factory(session_factory)

    global cache
    cache = CacheManager(**parse_cache_config_options(settings))

    from .authnz import APIKeyAuthenticationPolicy
    api_key_authn_policy = APIKeyAuthenticationPolicy()
    config.include('openstax_accounts')
    openstax_authn_policy = config.registry.getUtility(
        IOpenstaxAccountsAuthenticationPolicy)
    policies = [api_key_authn_policy, openstax_authn_policy]
    authn_policy = MultiAuthenticationPolicy(policies)
    config.set_authentication_policy(authn_policy)
    authz_policy = ACLAuthorizationPolicy()
    config.set_authorization_policy(authz_policy)

    config.scan(ignore='cnxpublishing.tests')
    return config.make_wsgi_app()
示例#13
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application."""
    session = SignedCookieSessionFactory('VALIDATE', hashalg='sha512')
    database_url = os.environ.get('DATABASE_URL', None)
    if database_url is not None:
        settings['sqlalchemy.url'] = database_url
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    authn_policy = AuthTktAuthenticationPolicy(
        'sosecret', hashalg='sha512')
    authz_policy = ACLAuthorizationPolicy()
    config = Configurator(settings=settings,
                          root_factory=DefaultRoot,)
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.set_session_factory(session)
    config.include('pyramid_jinja2')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('article', '/article/{article_id}')
    config.add_route('add_entry', '/add_entry')
    config.add_route('edit_entry', '/edit_entry/{article_id}')
    config.add_route('secure', '/secure')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.scan()
    return config.make_wsgi_app()
示例#14
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    if 'DATABASE_URL' in os.environ:
        settings['sqlalchemy.url'] = os.environ['DATABASE_URL']
    engine = engine_from_config(settings, 'sqlalchemy.')
    auth_secret = os.environ.get('AUTH_SECRET', 'secret')
    authn_policy = AuthTktAuthenticationPolicy(secret=auth_secret,
                                               hashalg='sha256')
    authz_policy = ACLAuthorizationPolicy()
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(settings=settings, root_factory=MyRoot)
    config.set_session_factory(SignedCookieSessionFactory('seekrit'))
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.include('pyramid_jinja2')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('index', '/')
    config.add_route('add', '/add')
    config.add_route('entry', '/entries/{id:\d+}')
    config.add_route('edit', '/entries/{id:\d+}/edit')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    # config.add_route('add_json', '/add_json')
    # config.add_route('entry_json', '/entry_json')
    config.scan()
    return config.make_wsgi_app()
示例#15
0
def main(global_config, **settings):
    """Returns a Pyramid WSGI application."""
    settings['sqlalchemy.url'] = SQLALCHEMY_URL
    settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager'
    config = Configurator(
        settings=settings,
        session_factory=SignedCookieSessionFactory('itsaseekreet'))
    config.include('.routes')
    config.include('pyramid_tm')
    config.include('pyramid_mako')
    config.include('pyramid_chameleon')
    config.add_view(create_task,
                    renderer=os.path.join(
                        os.path.dirname(os.path.abspath(__file__)),
                        'templates/form.pt'))
    config.add_static_view('static', 'deform:static')
    config.add_mako_renderer('.html')
    session_factory = get_session_factory(
        engine_from_config(settings, prefix='sqlalchemy.'))
    config.registry['dbsession_factory'] = session_factory
    config.add_request_method(
        lambda request: get_tm_session(session_factory, request.tm),
        'dbsession',
        reify=True)

    config.scan()
    return config.make_wsgi_app()
示例#16
0
文件: __init__.py 项目: T0MASD/keel
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application."""
    my_session_factory = SignedCookieSessionFactory('itsaseekreet', timeout=None)
    my_authentication_policy = SessionAuthenticationPolicy(callback=groupfinder, debug=False)
    my_authorization_policy = ACLAuthorizationPolicy()
    
    config = Configurator(settings=settings)
    config.set_root_factory(Root)
    config.set_session_factory(my_session_factory)
    config.set_authentication_policy(my_authentication_policy)
    config.set_authorization_policy(my_authorization_policy)

    # add mongo db
    config.add_subscriber(add_mongo_db, NewRequest)
    # add cors headers
    config.add_subscriber(add_cors_headers_response_callback, NewRequest)
    # add csrf token header
    config.add_subscriber(add_csrf_token_header, NewRequest)
    # add toaster notification header
    config.add_subscriber(add_toaster_notification_header, NewRequest)

    # override default json renderer
    config.add_renderer('json', MongoJSONRenderer) 

    config.add_route('options', '/*foo', request_method='OPTIONS') # matches any path OPTIONS method
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('auth', '/auth')
    config.add_route('search', '/search')
    config.scan()
    return config.make_wsgi_app()
示例#17
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    my_session_factory = SignedCookieSessionFactory('itsaseekreet')
    with Configurator(settings=settings,
                      session_factory=my_session_factory) as config:
        config.include('.models')
        config.include('cornice')
        config.include('pyramid_tm')
        config.include('pyramid_jinja2')
        config.add_jinja2_renderer('.html')
        config.include('.routes')
        config.include('.views')

        # Store the CSRF token in cookie as the Angular HttpClient reads
        # from the cookie to set the appropriate headers. Configure the
        # pyramid to use the same token name and X- header used by the
        # Angular
        csrf_policy = CookieCSRFStoragePolicy(cookie_name='XSRF-TOKEN')
        config.set_csrf_storage_policy(csrf_policy)
        config.set_default_csrf_options(require_csrf=True,
                                        token='XSRF-TOKEN',
                                        header='X-XSRF-TOKEN')

        config.scan()
        config.add_static_view(name='/', path=settings.get('client_url'))
    return config.make_wsgi_app()
示例#18
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config_path = global_config['__file__']
    config = configparser.ConfigParser()
    config.read(config_path)
    mode = config.get('app:main', 'mode')
    print(mode)
    InitSetting(mode)
    #db_url = config.get('app:main', 'sqlalchemy.url')
    config = Configurator(settings=settings)
    config.include('pyramid_chameleon')
    config.add_static_view(name='static', path='static', cache_max_age=0)
    config.add_static_view(name='website', path='../website', cache_max_age=0)

    config.add_route('test', '/test')
    config.add_route('home', '/')

    config.add_route('UpdateNews', '/UpdateNews')
    config.add_route('ExtractNews', '/ExtractNews')
    config.add_route('inn', '/inn/{one}/{two}')

    config.add_route('SignUp', '/SignUp')
    config.add_route('SignIn', '/SignIn')
    config.add_route('LogOut', '/LogOut')

    ys_session_factory = SignedCookieSessionFactory("thisissecretkay")
    config.set_session_factory(ys_session_factory)

    config.scan()
    return config.make_wsgi_app()
示例#19
0
def includeme(config):
    """
    Initialize the model for a Pyramid app.

    Activate this setup using ``config.include('stamper.models')``.

    """
    settings = config.get_settings()
    settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager'

    # use pyramid_tm to hook the transaction lifecycle to the request
    config.include('pyramid_tm')

    # use pyramid_retry to retry a request when transient exceptions occur
    config.include('pyramid_retry')

    db_session_factory = get_session_factory(get_engine(settings))
    config.registry['dbsession_factory'] = db_session_factory

    # make request.dbsession available for use in Pyramid
    config.add_request_method(
        # r.tm is the transaction manager used by pyramid_tm
        lambda r: get_tm_session(db_session_factory, r.tm),
        'dbsession',
        reify=True
    )

    session_factory = SignedCookieSessionFactory('itsaseekreet')

    # FIXME: Доработать до зашифровки сессии.

    config.set_session_factory(session_factory)
示例#20
0
def main(global_config, **settings):
    config = Configurator(settings=settings)
    session_factory = SignedCookieSessionFactory('deletebrig!')
    config.set_session_factory(session_factory)
    config.include('pyramid_chameleon')
    config.scan('.views')
    config.add_static_view(name='static', path='static/')
    config.add_route('home', '/')
    config.add_route('command', '/command/list/{id}')
    config.add_route('command_add', '/command/add')
    config.add_route('command_edit', '/command/edit/{id}')
    config.add_route('command_delete', '/command/delete/{id}')
    config.add_route('timer', '/timer/list/{id}')
    config.add_route('timer_add', '/timer/add')
    config.add_route('timer_edit', '/timer/edit/{id}')
    config.add_route('timer_delete', '/timer/delete/{id}')
    config.add_route('filter', '/filter/list/{id}')
    config.add_route('word_add', '/filter/add_word')
    config.add_route('word_edit', '/filter/edit_word/{id}')
    config.add_route('word_delete', '/filter/delete_word/{id}')
    config.add_route('url_add', '/filter/add_url')
    config.add_route('url_edit', '/filter/edit_url/{id}')
    config.add_route('url_delete', '/filter/delete_url/{id}')
    deform.renderer.configure_zpt_renderer()
    bot.start_timed_messages()
    bot.start()
    return config.make_wsgi_app()
示例#21
0
def main(global_config, **settings):
    settings['auth.secret'] = 'conference 2017 abstracts'
    settings['mako.directories'] = '%s:templates' % __name__

    authn_policy = AuthTktAuthenticationPolicy(settings['auth.secret'], )
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(
        settings=settings,
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
    )

    config.set_session_factory(
        SignedCookieSessionFactory(settings['auth.secret']))

    config.include("cornice")
    config.include('pyramid_mako')

    config.add_static_view('static', 'static', cache_max_age=0)

    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    #config.add_route('reauth','/reauth')

    config.scan("conference_abstract.auth")
    config.scan("conference_abstract.services")
    config.scan("conference_abstract.views")

    config.add_notfound_view(notfound)
    #config.add_exception_view(founderror)

    return config.make_wsgi_app()
示例#22
0
def main(global_config, **settings):
    config = Configurator(settings=settings)
    config.include('pyramid_jinja2')
    config.scan()
    config.include('pyramid_sqlalchemy')
    metadata.create_all()
    config.add_static_view(name='deform_static', path='deform:static')
    config.add_static_view(name='static', path='mysite:static')
    config.add_route('home', '/')
    config.add_route('todos_list', '/todos')
    config.add_route('todos_add', '/todos/add')
    config.add_route('todos_view', '/todos/{id}')
    config.add_route('todos_edit', '/todos/{id}/edit')
    config.add_route('todos_delete', '/todos/{id}/delete')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')

    session_secret = settings['session.secret']
    session_factory = SignedCookieSessionFactory(session_secret)
    config.set_session_factory(session_factory)

    # Security policies
    authn_policy = AuthTktAuthenticationPolicy(settings['auth.secret'],
                                               callback=groupfinder,
                                               hashalg='sha512')
    authz_policy = ACLAuthorizationPolicy()
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    return config.make_wsgi_app()
示例#23
0
def main():
    """Create a configured wsgi app"""
    settings = {}
    settings['reload_all'] = os.environ.get('DEBUG', True)
    settings['debug_all'] = os.environ.get('DEBUG', True)
    settings['sqlalchemy.url'] = os.environ.get(
        'DATABASE_URL', 'postgresql://{}:@localhost:5432/seattle'.format(USER))
    engine = sa.engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    settings['auth.username'] = os.environ.get('AUTH_USERNAME', 'admin')
    # secret value for session signing:
    secret = os.environ.get('JOURNAL_SESSION_SECRET', 'itsaseekrit')
    session_factory = SignedCookieSessionFactory(secret)
    # add a secret value for auth tkt signing
    auth_secret = os.environ.get('JOURNAL_AUTH_SECRET', 'anotherseekrit')
    # configuration setup
    config = Configurator(
        settings=settings,
        session_factory=session_factory,
        authentication_policy=AuthTktAuthenticationPolicy(secret=auth_secret,
                                                          hashalg='sha512'),
        authorization_policy=ACLAuthorizationPolicy(),
    )
    config.include('pyramid_jinja2')
    config.include('pyramid_tm')
    config.scan()
    app = config.make_wsgi_app()
    return app
示例#24
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    session_factory = SignedCookieSessionFactory('whateve', timeout=7200)

    config = Configurator(settings=settings)
    config.set_session_factory(session_factory)
    config.include('pyramid_chameleon')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('find_user', '/user/+me')
    config.add_route('login', '/login/openid/callback')
    config.add_route('search_user', '/user/+search')
    config.add_route('id_user', '/user/id/{id}')
    config.add_route('view_user', '/user/{username}')
    config.add_route('lock_review', '/review/{review}/lock')
    config.add_route('cbt_review_callback',
                     '/review/{review}/ctb_callback/{id}')
    config.add_route('test_review', '/review/{review}/test')
    config.add_route('show_review', '/review/{review}')
    config.add_route('query', '/search')
    config.add_route('query_results', '/search/{filter}')
    config.scan()
    add_ubuntu_login(config)

    return config.make_wsgi_app()
示例#25
0
def make_app(global_settings: dict, **settings: dict) -> Router:

    session_factory = SignedCookieSessionFactory(settings["zam.secret"])

    with Configurator(settings=settings,
                      root_factory=Root,
                      session_factory=session_factory) as config:

        config.include("pyramid_tm")

        engine = engine_from_config(settings, "sqlalchemy.")
        DBSession.configure(bind=engine)
        Base.metadata.bind = engine
        config.include("pyramid_default_cors")

        config.include("pyramid_jinja2")
        config.add_jinja2_renderer(".html")
        config.add_jinja2_search_path("zam_repondeur:templates", name=".html")

        config.add_route("choices_lectures", "/choices/dossiers/{uid}/")

        config.add_static_view("static", "static", cache_max_age=3600)

        config.scan()

        load_data(config)
        load_version(config)

        app = config.make_wsgi_app()

    return app
示例#26
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    config = Configurator(settings=settings)
    my_session_factory = SignedCookieSessionFactory('itsaseekreet')
    config.set_session_factory(my_session_factory)
    authn_policy = AuthTktAuthenticationPolicy(settings['fidel.secret'],
                                               hashalg='sha512')
    authz_policy = ACLAuthorizationPolicy()
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    config.include('pyramid_jinja2')
    config.add_static_view(name='static', path='fidel:static')
    config.add_route('home', '/')
    config.add_route('admin', '/admin')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('create_user', '/create_user')
    config.add_route('add_user', '/add_user')
    config.add_route('map_zones', '/map_zones')
    config.add_route('map_propierties', '/map_propierties')
    config.add_route('add_zone', '/add_zone')
    config.add_route('show_zones', '/zones{barra:/?}{page:[0-9]*}')
    config.add_route('delete_zone', '/zones/delete_zone')
    config.add_route('show_zone', '/zones/zone')
    config.scan()
    return config.make_wsgi_app()
示例#27
0
def _getSessionClass():
    """Defer initializing session class parameters at import time.

    Wait until ZCA is available.
    """
    global ZopeCookieSession

    if ZopeCookieSession is None:
        config = getUtility(ISignedSessionCookieConfig)
        attrs = config.getCookieAttrs()
        if 'serializer' in attrs:
            PyramidCookieSession = BaseCookieSessionFactory(**attrs)
        else:
            PyramidCookieSession = SignedCookieSessionFactory(**attrs)

        class ZopeCookieSession(PyramidCookieSession):
            """Wrap Pyramid's class, adding Zope2 security majyk.
            """
            security = ClassSecurityInfo()
            security.setDefaultAccess('allow')
            security.declareObjectPublic()

            def __guarded_getitem__(self, key):
                return self[key]

            def __guarded_setitem__(self, key, value):
                self[key] = value

            def __guarded_delitem__(self, key):
                del self[key]

        InitializeClass(ZopeCookieSession)

    return ZopeCookieSession
示例#28
0
def includeme(config):
    """Set up the app's Pyramid session."""
    # ``secure=True`` is recommended by the Pyramid docs (see
    # https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/sessions.html)
    # but is inconvenient in development environments, so use insecure cookies
    # in dev for convenience but use secure (HTTPS-only) cookies otherwise.
    secure = not config.registry.settings.get("debug", False)

    config.set_session_factory(
        SignedCookieSessionFactory(
            secret=config.registry.settings["session_cookie_secret"],
            secure=secure,
            # ``httponly=True`` is recommended by the Pyramid docs to protect
            # the cookie from cross-site scripting vulnerabilities, see:
            # https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/sessions.html
            httponly=True,
            # This is the timeout and reissue time recommended in the Pyramid
            # docs for auto-expiring cookies. See:
            # https://docs.pylonsproject.org/projects/pyramid/en/latest/api/session.html
            timeout=1200,
            reissue_time=120,
            # The Pyramid docs recommend JSONSerializer instead of the default
            # serializer for security reasons. See:
            # https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/sessions.html
            serializer=JSONSerializer(),
        ))
示例#29
0
def session(config):
    """ To create a session secret on the server:

    $ cat /dev/urandom | head -c 256 | base64 > session-secret.b64
    """
    settings = config.registry.settings
    if 'session.secret' in settings:
        secret = settings['session.secret'].strip()
        if secret.startswith('/'):
            secret = open(secret).read()
            secret = base64.b64decode(secret)
    else:
        secret = os.urandom(256)
    # auth_tkt has no timeout set
    # cookie will still expire at browser close
    if 'session.timeout' in settings:
        timeout = int(settings['session.timeout'])
    else:
        timeout = 60 * 60 * 24
    session_factory = SignedCookieSessionFactory(
        secret=secret,
        timeout=timeout,
        reissue_time=2**32,  # None does not work
        serializer=JSONSerializer(),
    )
    config.set_session_factory(session_factory)
示例#30
0
文件: __init__.py 项目: kashifpk/PyCK
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    load_project_settings()

    session_factory = SignedCookieSessionFactory(
        settings.get('session.secret', 'hello'))

    engine = engine_from_config(settings, 'sqlalchemy.')
    db.configure(bind=engine)
    config = Configurator(session_factory=session_factory, settings=settings)
    config.add_tween('pycktestproject.auth.authenticator')
    config.include('pyramid_mako')
    config.add_view('pyramid.view.append_slash_notfound_view',
                    context='pyramid.httpexceptions.HTTPNotFound')

    add_admin_handler(config, db, get_models(pycktestproject,
                                             return_dict=True), 'admin.',
                      '/admin', AdminController)

    application_routes(config)
    configure_app_routes(config)

    all_apps = get_submodules(apps)

    ignored_apps = []
    enabled_app_names = [subapp.APP_NAME for subapp in enabled_apps]
    for app in all_apps:
        if app['is_package'] and app['name'] not in enabled_app_names:
            ignored_apps.append('.apps.' + app['name'])

    config.scan(ignore=ignored_apps)

    return config.make_wsgi_app()