Python beaker.middleware.SessionMiddleware() Examples
The following are 4
code examples of beaker.middleware.SessionMiddleware().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
beaker.middleware
, or try the search function
.
Example #1
Source File: test_login.py From oncall with BSD 2-Clause "Simplified" License | 5 votes |
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()
Example #2
Source File: app.py From oncall with BSD 2-Clause "Simplified" License | 5 votes |
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)
Example #3
Source File: __init__.py From iris with BSD 2-Clause "Simplified" License | 4 votes |
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
Example #4
Source File: app.py From refstack with Apache License 2.0 | 4 votes |
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