flows: use global logger for stored plans

This commit is contained in:
Jens Langhammer 2021-02-02 17:28:06 +01:00
parent 0114bc0d6a
commit 3e696d6ac8
2 changed files with 4 additions and 9 deletions

View File

@ -15,6 +15,7 @@ from authentik.flows.markers import ReevaluateMarker, StageMarker
from authentik.flows.models import Flow, FlowStageBinding, Stage from authentik.flows.models import Flow, FlowStageBinding, Stage
from authentik.policies.engine import PolicyEngine from authentik.policies.engine import PolicyEngine
LOGGER = get_logger()
PLAN_CONTEXT_PENDING_USER = "pending_user" PLAN_CONTEXT_PENDING_USER = "pending_user"
PLAN_CONTEXT_SSO = "is_sso" PLAN_CONTEXT_SSO = "is_sso"
PLAN_CONTEXT_REDIRECT = "redirect" PLAN_CONTEXT_REDIRECT = "redirect"
@ -41,8 +42,6 @@ class FlowPlan:
context: Dict[str, Any] = field(default_factory=dict) context: Dict[str, Any] = field(default_factory=dict)
markers: List[StageMarker] = field(default_factory=list) markers: List[StageMarker] = field(default_factory=list)
_logger: BoundLogger = field(default_factory=get_logger)
def append(self, stage: Stage, marker: Optional[StageMarker] = None): def append(self, stage: Stage, marker: Optional[StageMarker] = None):
"""Append `stage` to all stages, optionall with stage marker""" """Append `stage` to all stages, optionall with stage marker"""
self.stages.append(stage) self.stages.append(stage)
@ -56,14 +55,10 @@ class FlowPlan:
marker = self.markers[0] marker = self.markers[0]
if marker.__class__ is not StageMarker: if marker.__class__ is not StageMarker:
self._logger.debug( LOGGER.debug("f(plan_inst): stage has marker", stage=stage, marker=marker)
"f(plan_inst): stage has marker", stage=stage, marker=marker
)
marked_stage = marker.process(self, stage, http_request) marked_stage = marker.process(self, stage, http_request)
if not marked_stage: if not marked_stage:
self._logger.debug( LOGGER.debug("f(plan_inst): marker returned none, next stage", stage=stage)
"f(plan_inst): marker returned none, next stage", stage=stage
)
self.stages.remove(stage) self.stages.remove(stage)
self.markers.remove(marker) self.markers.remove(marker)
if not self.has_stages: if not self.has_stages:

View File

@ -52,7 +52,7 @@ class FlowExecutorView(View):
_logger: BoundLogger _logger: BoundLogger
def setup(self, request: HttpRequest, flow_slug: str): def setup(self, request: HttpRequest, flow_slug: str):
super().setup(request) super().setup(request, flow_slug=flow_slug)
self.flow = get_object_or_404(Flow.objects.select_related(), slug=flow_slug) self.flow = get_object_or_404(Flow.objects.select_related(), slug=flow_slug)
self._logger = get_logger().bind(flow_slug=flow_slug) self._logger = get_logger().bind(flow_slug=flow_slug)