当前位置: 首页>>代码示例>>Python>>正文


Python middleware.SessionMiddleware方法代码示例

本文整理汇总了Python中beaker.middleware.SessionMiddleware方法的典型用法代码示例。如果您正苦于以下问题:Python middleware.SessionMiddleware方法的具体用法?Python middleware.SessionMiddleware怎么用?Python middleware.SessionMiddleware使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在beaker.middleware的用法示例。


在下文中一共展示了middleware.SessionMiddleware方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from beaker import middleware [as 别名]
# 或者: from beaker.middleware import SessionMiddleware [as 别名]
def setUp(self):
        super(TestLogin, self).setUp()
        login.auth_manager = self.DummyAuthenticator()
        api = falcon.API(middleware=[
            ReqBodyMiddleware(),
        ])
        api.req_options.auto_parse_form_urlencoded = False
        self.api = api
        self.api.add_route('/login', login)
        self.api.add_route('/logout', logout)
        self.api.add_route('/dummy/{user}', self.UserDummy())
        self.api.add_route('/dummy2/{team}', self.TeamDummy())
        self.api = SessionMiddleware(self.api, self.session_opts)

        self.user_name = 'test_login_user'
        self.admin_name = 'test_login_admin'
        self.team_name = 'test_login_team'

        connection = db.connect()
        cursor = connection.cursor()
        # Create users
        cursor.execute("INSERT INTO `user` (`name`, `active`) VALUES (%s, 1)", self.user_name)
        self.user_id = cursor.lastrowid
        cursor.execute("INSERT INTO `user` (`name`, `active`) VALUES (%s, 1)", self.admin_name)
        self.admin_id = cursor.lastrowid

        # Set up team
        cursor.execute("INSERT INTO `team` (`name`) VALUES (%s)", self.team_name)
        self.team_id = cursor.lastrowid
        cursor.execute("INSERT INTO `team_user` VALUES (%s, %s)", (self.team_id, self.user_id))
        cursor.execute("INSERT INTO `team_user` VALUES (%s, %s)", (self.team_id, self.admin_id))
        cursor.execute("INSERT INTO `team_admin` VALUES (%s, %s)", (self.team_id, self.admin_id))

        connection.commit()
        cursor.close()
        connection.close() 
开发者ID:linkedin,项目名称:oncall,代码行数:38,代码来源:test_login.py

示例2: init

# 需要导入模块: from beaker import middleware [as 别名]
# 或者: from beaker.middleware import SessionMiddleware [as 别名]
def init(config):
    db.init(config['db'])
    constants.init(config)
    if 'iris_plan_integration' in config:
        iris.init(config['iris_plan_integration'])

    if not config.get('debug', False):
        security_headers.append(
            ("Content-Security-Policy",
             # unsafe-eval is required for handlebars without precompiled templates
             "default-src 'self' %s 'unsafe-eval' ; "
             "font-src 'self' data: blob; img-src data: uri https: http:; "
             "style-src 'unsafe-inline' https: http:;" %
             config.get('iris_plan_integration', {}).get('api_host', '')))
        logging.basicConfig(level=logging.INFO)
        logger.info('%s', security_headers)
    else:
        logging.basicConfig(level=logging.DEBUG)

    init_falcon_api(config)

    global application
    session_opts = {
        'session.type': 'cookie',
        'session.cookie_expires': True,
        'session.key': 'oncall-auth',
        'session.encrypt_key': config['session']['encrypt_key'],
        'session.validate_key': config['session']['sign_key'],
        'session.secure': not (config.get('debug', False) or config.get('allow_http', False)),
        'session.httponly': True,
        'session.crypto_type': 'cryptography'
    }
    application = SessionMiddleware(application, session_opts)
    application = RawPathPatcher(application) 
开发者ID:linkedin,项目名称:oncall,代码行数:36,代码来源:app.py

示例3: init

# 需要导入模块: from beaker import middleware [as 别名]
# 或者: from beaker.middleware import SessionMiddleware [as 别名]
def init(config, app):
    global local_api_url
    logger.info('Web asset root: "%s"', ui_root)
    auth_module = config.get('auth', {'module': 'iris.ui.auth.noauth'})['module']
    auth = importlib.import_module(auth_module)
    auth_manager = getattr(auth, 'Authenticator')(config)
    qr_base_url = config.get('qr_base_url')
    qr_login_url = config.get('qr_login_url')

    debug = config['server'].get('disable_auth', False) is True
    local_api_url = config['server'].get('local_api_url', 'http://localhost:16649')

    app.add_route('/static/bundles/{filename}', StaticResource('/static/bundles'))
    app.add_route('/static/images/{filename}', StaticResource('/static/images'))
    app.add_route('/static/fonts/{filename}', StaticResource('/static/fonts'))
    app.add_route('/', Index())
    app.add_route('/stats', Stats())
    app.add_route('/stats/{application}', AppStats())
    app.add_route('/singlestats/{stat_name}', SingleStats())
    app.add_route('/plans/', Plans())
    app.add_route('/plans/{plan}', Plan())
    app.add_route('/incidents/', Incidents())
    app.add_route('/incidents/{incident}', Incident())
    app.add_route('/messages/', Messages())
    app.add_route('/messages/{message}', Message())
    app.add_route('/templates/', Templates())
    app.add_route('/templates/{template}', Template())
    app.add_route('/applications/', Applications())
    app.add_route('/applications/{application}', Application())
    app.add_route('/login/', Login(auth_manager, debug))
    app.add_route('/logout/', Logout())
    app.add_route('/user/', User())
    app.add_route('/validate/jinja', JinjaValidate())
    app.add_route('/unsubscribe/{application}', Unsubscribe())

    if(qr_base_url and qr_login_url):
        create_qr_code(qr_base_url, qr_login_url)
        app.add_route('/qr', Qr(qr_base_url, qr_login_url))

    # Configuring the beaker middleware mutilates the app object, so do it
    # at the end, after we've added all routes/sinks for the entire iris
    # app.
    session_opts = {
        'session.type': 'cookie',
        'session.cookie_expires': True,
        'session.key': 'iris-auth',
        'session.encrypt_key': config['user_session']['encrypt_key'],
        'session.validate_key': config['user_session']['sign_key'],
        'session.secure': not (config['server'].get('disable_auth', False) or config['server'].get('allow_http', False)),
        'session.httponly': True,
        'session.crypto_type': 'cryptography',
        'session.samesite': 'Lax'
    }
    app = SessionMiddleware(app, session_opts)

    return app 
开发者ID:linkedin,项目名称:iris,代码行数:58,代码来源:__init__.py

示例4: setup_app

# 需要导入模块: from beaker import middleware [as 别名]
# 或者: from beaker.middleware import SessionMiddleware [as 别名]
def setup_app(config):
    """App factory."""
    # By default we expect path to oslo config file in environment variable
    # REFSTACK_OSLO_CONFIG (option for testing and development)
    # If it is empty we look up those config files
    # in the following directories:
    #   ~/.${project}/
    #   ~/
    #   /etc/${project}/
    #   /etc/

    default_config_files = ((os.getenv('REFSTACK_OSLO_CONFIG'), )
                            if os.getenv('REFSTACK_OSLO_CONFIG')
                            else cfg.find_config_files('refstack'))
    CONF('',
         project='refstack',
         default_config_files=default_config_files)

    log.setup(CONF, 'refstack')
    CONF.log_opt_values(LOG, logging.DEBUG)

    template_path = CONF.api.template_path % {'project_root': PROJECT_ROOT}
    static_root = CONF.api.static_root % {'project_root': PROJECT_ROOT}
    app_conf = dict(config.app)
    app = pecan.make_app(
        app_conf.pop('root'),
        debug=CONF.api.app_dev_mode,
        static_root=static_root,
        template_path=template_path,
        hooks=[
            JWTAuthHook(), JSONErrorHook(), CORSHook(),
            pecan.hooks.RequestViewerHook(
                {'items': ['status', 'method', 'controller', 'path', 'body']},
                headers=False, writer=WritableLogger(LOG, logging.DEBUG)
            )
        ]
    )

    beaker_conf = {
        'session.key': 'refstack',
        'session.type': 'ext:database',
        'session.url': CONF.database.connection,
        'session.timeout': 604800,
        'session.validate_key': api_utils.get_token(),
        'session.sa.pool_recycle': 600
    }
    app = SessionMiddleware(app, beaker_conf)

    if CONF.api.app_dev_mode:
        LOG.debug('\n\n <<< Refstack UI is available at %s >>>\n\n',
                  CONF.ui_url)

    return app 
开发者ID:openstack-archive,项目名称:refstack,代码行数:55,代码来源:app.py


注:本文中的beaker.middleware.SessionMiddleware方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。