@@ -38,10 +38,7 @@ def add_path(url, path):
3838
3939
4040def init_user_info (conf , cwd ):
41- try :
42- kwargs = conf ["kwargs" ]
43- except KeyError :
44- kwargs = {}
41+ kwargs = conf .get ("kwargs" , {})
4542
4643 if "db_file" in kwargs :
4744 kwargs ["db_file" ] = os .path .join (cwd , kwargs ["db_file" ])
@@ -53,10 +50,7 @@ def init_user_info(conf, cwd):
5350
5451
5552def init_service (conf , endpoint_context = None ):
56- try :
57- kwargs = conf ["kwargs" ]
58- except KeyError :
59- kwargs = {}
53+ kwargs = conf .get ("kwargs" , {})
6054
6155 if endpoint_context :
6256 kwargs ["endpoint_context" ] = endpoint_context
@@ -137,11 +131,10 @@ def __init__(
137131
138132 # session db
139133 self ._sub_func = {}
140- self .do_sub_func (self . conf )
134+ self .do_sub_func ()
141135 self .sdb = session_db
142136 if not self .sdb :
143137 self .set_session_db (conf , sso_db )
144- #
145138
146139 self .scope2claims = SCOPE2CLAIMS
147140
@@ -202,15 +195,15 @@ def __init__(
202195 for item in ['cookie_dealer' , "authz" , "authentication" , "id_token" , "scope2claims" ]:
203196 _func = getattr (self , "do_{}" .format (item ), None )
204197 if _func :
205- _func (self . conf )
198+ _func ()
206199
207- _cap = self .do_endpoints (conf )
200+ _cap = self .do_endpoints ()
208201
209202 for item in ["userinfo" , "login_hint_lookup" , "login_hint2acrs" ,
210203 "add_on" ]:
211204 _func = getattr (self , "do_{}" .format (item ), None )
212205 if _func :
213- _func (self . conf )
206+ _func ()
214207
215208 self .provider_info = self .create_providerinfo (_cap )
216209
@@ -228,75 +221,65 @@ def set_session_db(self, conf, sso_db=None):
228221 sso_db = sso_db if sso_db else SSODb ()
229222 self .do_session_db (conf , sso_db )
230223 # this append useinfo db to the session db
231- self .do_userinfo (conf )
224+ self .do_userinfo ()
232225 logger .debug ('Session DB: {}' .format (self .sdb .__dict__ ))
233226
234- def do_add_on (self , conf ):
235- if 'add_on' in conf :
236- for spec in conf ["add_on" ].values ():
227+ def do_add_on (self ):
228+ _conf = self .conf .get ("add_on" )
229+ if 'add_on' in self .conf :
230+ for spec in self .conf ["add_on" ].values ():
237231 if isinstance (spec ["function" ], str ):
238232 _func = importer (spec ["function" ])
239233 else :
240234 _func = spec ["function" ]
241235
242236 _func (self .endpoint , ** spec ["kwargs" ])
243237
244- def do_login_hint2acrs (self , conf ):
245- try :
246- _conf = conf ["login_hint2acrs" ]
247- except KeyError :
248- self .login_hint2acrs = None
249- else :
250- self .login_hint2acrs = init_service (_conf )
238+ def do_login_hint2acrs (self ):
239+ _conf = self .conf .get ("login_hint2acrs" )
251240
252- def do_login_hint_lookup (self , conf ):
253- try :
254- _conf = conf ["login_hint_lookup" ]
255- except KeyError :
256- pass
241+ if _conf :
242+ self .login_hint2acrs = init_service (_conf )
257243 else :
244+ self .login_hint2acrs = None
245+
246+ def do_login_hint_lookup (self ):
247+ _conf = self .conf .get ("login_hint_lookup" )
248+ if _conf :
258249 self .login_hint_lookup = init_service (_conf )
259250 if self .userinfo :
260251 self .login_hint_lookup .user_info = self .userinfo
261252
262- def do_userinfo (self , conf ):
263- try :
264- _conf = conf ["userinfo" ]
265- except KeyError :
266- pass
267- else :
253+ def do_userinfo (self ):
254+ _conf = self .conf .get ("userinfo" )
255+ if _conf :
268256 if self .sdb :
269257 self .userinfo = init_user_info (_conf , self .cwd )
270258 self .sdb .userinfo = self .userinfo
271259
272260
273- def do_id_token (self , conf ):
274- try :
275- _conf = conf ["id_token" ]
276- except KeyError :
277- self .idtoken = IDToken (self )
278- else :
261+ def do_id_token (self ):
262+ _conf = self .conf .get ("id_token" )
263+ if _conf :
279264 self .idtoken = init_service (_conf , self )
280-
281- def do_authentication (self , conf ):
282- try :
283- _authn = conf ["authentication" ]
284- except KeyError :
285- self .authn_broker = None
286265 else :
287- self .authn_broker = populate_authn_broker ( _authn , self , self . template_handler )
266+ self .idtoken = IDToken ( self )
288267
289- def do_cookie_dealer (self , conf ):
290- try :
291- _conf = conf ['cookie_dealer' ]
292- except KeyError :
293- pass
268+ def do_authentication (self ):
269+ _conf = self .conf .get ("authentication" )
270+ if _conf :
271+ self .authn_broker = populate_authn_broker (_conf , self , self .template_handler )
294272 else :
273+ self .authn_broker = None
274+
275+ def do_cookie_dealer (self ):
276+ _conf = self .conf .get ('cookie_dealer' )
277+ if _conf :
295278 if not self .cookie_dealer :
296279 self .cookie_dealer = init_service (_conf )
297280
298- def do_sub_func (self , conf ):
299- _conf = conf .get ("sub_func" , {})
281+ def do_sub_func (self ):
282+ _conf = self . conf .get ("sub_func" , {})
300283 for key , args in _conf .items ():
301284 if "class" in args :
302285 self ._sub_func [key ] = init_service (args )
@@ -314,17 +297,15 @@ def do_session_db(self, conf, sso_db):
314297 sub_func = self ._sub_func
315298 )
316299
317- def do_endpoints (self , conf ):
300+ def do_endpoints (self ):
318301 self .endpoint = build_endpoints (
319- conf ["endpoint" ],
302+ self . conf ["endpoint" ],
320303 endpoint_context = self ,
321304 client_authn_method = CLIENT_AUTHN_METHOD ,
322- issuer = conf ["issuer" ],
305+ issuer = self . conf ["issuer" ],
323306 )
324- try :
325- _cap = conf ["capabilities" ]
326- except KeyError :
327- _cap = {}
307+
308+ _cap = self .conf .get ("capabilities" , {})
328309
329310 for endpoint , endpoint_instance in self .endpoint .items ():
330311 if endpoint_instance .provider_info :
@@ -338,13 +319,12 @@ def do_endpoints(self, conf):
338319
339320 return _cap
340321
341- def do_authz (self , conf ):
342- try :
343- authz_spec = conf ["authz" ]
344- except KeyError :
345- self .authz = authz .Implicit (self )
346- else :
322+ def do_authz (self ):
323+ authz_spec = self .conf .get ("authz" )
324+ if authz_spec :
347325 self .authz = init_service (authz_spec , self )
326+ else :
327+ self .authz = authz .Implicit (self )
348328
349329 def claims_supported (self ):
350330 _claims = set ()
0 commit comments