Skip to content

Commit d7e4572

Browse files
committed
Set target_frontend after handling the disco response
When the processing of the request micro-services is finished, the context is switched from the frontend to the backend. At that point target_frontend is needed to set the state of the router. The router state will be used when the processing of the response by the response micro-services is finished, to find the appropriate frontend instance. --- The routing state is set at the point when the switch from the frontend (and request micro-service processing) is made towards the backend. If the discovery response was not intercepted by the DiscoToTargetIssuer micro-service, and instead was processed by the backend's disco-response handler, the target_frontend would not be needed, as the routing state would have already been set. When the DiscoToTargetIssuer micro-service intercepts the response, the point when the switch from the frontend to the backend happens will be executed again. Due to leaving the proxy, going to the discovery service and coming back to the proxy, context.target_frontend has been lost. Only the state stored within context.state persists (through the cookie). --- When the request micro-services finish processing the request, backend_routing is called, which sets the router state (context.state['ROUTER']) to target_frontend, and returns the appropriate backend instance based on target_backend. When the time comes to switch from the backend to the frontend, that state is looked up (see below). When the response micro-services finish processing the response, frontend_routing is called, which sets target_frontend from the router state (context.state['ROUTER']) and returns the appropriate frontend instance based on target_frontend. --- Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent c0265f2 commit d7e4572

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/satosa/micro_services/disco.py

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ def __init__(self, config:dict, *args, **kwargs):
1717
if not isinstance(self.disco_endpoints, list) or not self.disco_endpoints:
1818
raise DiscoToTargetIssuerError('disco_endpoints must be a list of str')
1919

20+
def process(self, context:Context, data:InternalData):
21+
context.state[self.name] = {
22+
'target_frontend': context.target_frontend,
23+
'internal_data': data.to_dict(),
24+
}
25+
return super().process(context, data)
26+
2027
def register_endpoints(self):
2128
"""
2229
URL mapping of additional endpoints this micro service needs to register for callbacks.
@@ -42,7 +49,10 @@ def _handle_disco_response(self, context:Context):
4249
if not target_issuer:
4350
raise DiscoToTargetIssuerError('no valid entity_id in the disco response')
4451

52+
target_frontend = context.state.get(self.name, {}).get('target_frontend')
4553
data_serialized = context.state.get(self.name, {}).get('internal_data', {})
4654
data = InternalData.from_dict(data_serialized)
55+
56+
context.target_frontend = target_frontend
4757
context.decorate(Context.KEY_TARGET_ENTITYID, target_issuer)
4858
return super().process(context, data)

0 commit comments

Comments
 (0)