def __init__( self, # The Flask application to analyze app: Flask, # The HowFast app ID to use app_id: str = None, # Endpoints not to monitor endpoints_blacklist: List[str] = None, # Other configuration parameters passed to the CoreAPM constructor **kwargs, ): super().__init__(**kwargs) self.app = app self.wsgi_app = app.wsgi_app # We need to store thread local information, let's use Werkzeug's context locals # (see https://werkzeug.palletsprojects.com/en/1.0.x/local/) self.local = local.Local() self.local_manager = local.LocalManager([self.local]) # Overwrite the passed WSGI application app.wsgi_app = self.local_manager.make_middleware(self) if endpoints_blacklist: self.endpoints_blacklist = compile_endpoints(*endpoints_blacklist) else: self.endpoints_blacklist = [] # Setup the queue and the background thread self.setup(app_id) request_started.connect(self._request_started)
def wrap(wsgi_app, protect): """Wrap FLASK app in webauthd middleware.""" _LOGGER.info('Loading spnego auth.') unprotected_paths = ['/'] unprotected_methods = ['OPTIONS'] protected_paths = [] if protect: protected_paths.extend(protect) local_manager = local.LocalManager([SpnegoAuth.LOCALS]) app = SpnegoAuth(wsgi_app, protected_paths=protected_paths, unprotected_paths=unprotected_paths, unprotected_methods=unprotected_methods, unprotected_is_regex=False) return local_manager.make_middleware(app)
def test_custom_idents(): ident = 0 l = local.Local() stack = local.LocalStack() local.LocalManager([l, stack], ident_func=lambda: ident) l.foo = 42 stack.push({'foo': 42}) ident = 1 l.foo = 23 stack.push({'foo': 23}) ident = 0 assert l.foo == 42 assert stack.top['foo'] == 42 stack.pop() assert stack.top is None ident = 1 assert l.foo == 23 assert stack.top['foo'] == 23 stack.pop() assert stack.top is None
def test_custom_idents(): ident = 0 ns = local.Local() stack = local.LocalStack() local.LocalManager([ns, stack], ident_func=lambda: ident) ns.foo = 42 stack.push({"foo": 42}) ident = 1 ns.foo = 23 stack.push({"foo": 23}) ident = 0 assert ns.foo == 42 assert stack.top["foo"] == 42 stack.pop() assert stack.top is None ident = 1 assert ns.foo == 23 assert stack.top["foo"] == 23 stack.pop() assert stack.top is None