Skip to content

Commit f22d38c

Browse files
committed
feat: added process method to work even without a registered endpoint
1 parent 603c03f commit f22d38c

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/satosa/micro_services/custom_routing.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,30 @@ def _get_backend(self, context:str, entity_id:str) -> str:
6969
self.default_backend
7070
)
7171

72-
def backend_by_entityid(self, context):
72+
def process(self, context, data):
73+
"""
74+
Will modify the context.target_backend attribute based on the target entityid.
75+
:param context: request context
76+
:param data: the internal request
77+
"""
7378
entity_id = context.request.get('entityID')
79+
if entity_id:
80+
self._rewrite_context(entity_id, context)
81+
return super().process(context, data)
82+
83+
def _rewrite_context(self, entity_id, context) -> None:
7484
tr_backend = self._get_backend(context, entity_id)
85+
context.internal_data['target_entity_id'] = entity_id
86+
context.target_frontend = context.target_frontend or context.state['ROUTER']
87+
native_backend = context.target_backend
88+
msg = (f'Found DecideBackendByTarget ({self.name} microservice) '
89+
f'redirecting {entity_id} from {native_backend} '
90+
f'backend to {tr_backend}')
91+
logger.info(msg)
92+
context.target_backend = tr_backend
93+
94+
def backend_by_entityid(self, context):
95+
entity_id = context.request.get('entityID')
7596

7697
if not context.state.get('ROUTER'):
7798
raise SATOSAStateError(
@@ -80,14 +101,7 @@ def backend_by_entityid(self, context):
80101
)
81102

82103
if entity_id:
83-
context.internal_data['target_entity_id'] = entity_id
84-
context.target_frontend = context.state['ROUTER']
85-
native_backend = context.target_backend
86-
msg = (f'Found DecideBackendByTarget ({self.name} microservice) '
87-
f'redirecting {entity_id} from {native_backend} '
88-
f'backend to {tr_backend}')
89-
logger.info(msg)
90-
context.target_backend = tr_backend
104+
self._rewrite_context(entity_id, context)
91105
else:
92106
raise CustomRoutingError(
93107
f"{self.__class__.__name__} "

0 commit comments

Comments
 (0)