@@ -69,9 +69,30 @@ def _get_backend(self, context:str, entity_id:str) -> str:
69
69
self .default_backend
70
70
)
71
71
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
+ """
73
78
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 :
74
84
tr_backend = self ._get_backend (context , entity_id )
85
+ context .internal_data ['target_entity_id' ] = entity_id
86
+ context .target_frontend = 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' )
75
96
76
97
if not context .state .get ('ROUTER' ):
77
98
raise SATOSAStateError (
@@ -80,14 +101,7 @@ def backend_by_entityid(self, context):
80
101
)
81
102
82
103
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 (self , entity_id , context )
91
105
else :
92
106
raise CustomRoutingError (
93
107
f"{ self .__class__ .__name__ } "
0 commit comments