7
7
from .base import RequestMicroService
8
8
from ..exception import SATOSAConfigurationError
9
9
from ..exception import SATOSAError
10
- from ..exception import SATOSAStateError
11
10
12
11
13
12
logger = logging .getLogger (__name__ )
14
13
15
14
16
15
class CustomRoutingError (SATOSAError ):
17
- """
18
- SATOSA exception raised by CustomRouting rules
19
- """
16
+ """SATOSA exception raised by CustomRouting rules"""
20
17
pass
21
18
22
19
23
- class DecideBackendByTargetIdP (RequestMicroService ):
20
+ class DecideBackendByTargetIssuer (RequestMicroService ):
24
21
"""
25
22
Select target backend based on the target issuer.
26
23
"""
@@ -38,14 +35,11 @@ def __init__(self, config:dict, *args, **kwargs):
38
35
self .default_backend = config ['default_backend' ]
39
36
40
37
def process (self , context :Context , data :InternalData ):
41
- """
42
- Set context.target_backend based on the target issuer (context.target_entity_id)
38
+ """Set context.target_backend based on the target issuer"""
43
39
44
- :param context: request context
45
- :param data: the internal request
46
- """
47
40
target_issuer = context .get_decoration (Context .KEY_TARGET_ENTITYID )
48
41
if not target_issuer :
42
+ logger .info ('skipping backend decision because no target_issuer was found' )
49
43
return super ().process (context , data )
50
44
51
45
target_backend = (
@@ -64,45 +58,6 @@ def process(self, context:Context, data:InternalData):
64
58
return super ().process (context , data )
65
59
66
60
67
- class DecideBackendByDiscoIdP (DecideBackendByTargetIdP ):
68
- def __init__ (self , config :dict , * args , ** kwargs ):
69
- super ().__init__ (config , * args , ** kwargs )
70
-
71
- self .disco_endpoints = config ['disco_endpoints' ]
72
- if not isinstance (self .disco_endpoints , list ):
73
- raise CustomRoutingError ('disco_endpoints must be a list of str' )
74
-
75
- def register_endpoints (self ):
76
- """
77
- URL mapping of additional endpoints this micro service needs to register for callbacks.
78
-
79
- Example of a mapping from the url path '/callback' to the callback() method of a micro service:
80
- reg_endp = [
81
- ("^/callback1$", self.callback),
82
- ]
83
-
84
- :rtype List[Tuple[str, Callable[[satosa.context.Context, Any], satosa.response.Response]]]
85
-
86
- :return: A list with functions and args bound to a specific endpoint url,
87
- [(regexp, Callable[[satosa.context.Context], satosa.response.Response]), ...]
88
- """
89
-
90
- return [
91
- (path , self ._handle_disco_response )
92
- for path in self .disco_endpoints
93
- ]
94
-
95
- def _handle_disco_response (self , context :Context ):
96
- target_issuer_from_disco = context .request .get ('entityID' )
97
- if not target_issuer_from_disco :
98
- raise CustomRoutingError ('no valid entity_id in the disco response' )
99
-
100
- context .decorate (Context .KEY_TARGET_ENTITYID , target_issuer_from_disco )
101
- data_serialized = context .state .get (self .name , {}).get ('internal' , {})
102
- data = InternalData .from_dict (data_serialized )
103
- return self .process (context , data )
104
-
105
-
106
61
class DecideBackendByRequester (RequestMicroService ):
107
62
"""
108
63
Select which backend should be used based on who the requester is.
0 commit comments