65
65
}
66
66
},
67
67
},
68
- "httpc_params" : {"verify" : False },
68
+ "httpc_params" : {"verify" : False , "timeout" : 4 },
69
69
"issuer" : "https://{domain}:{port}" ,
70
70
"template_dir" : "templates" ,
71
71
"token_handler_args" : {
@@ -105,9 +105,6 @@ def add_base_path(conf: Union[dict, str], base_path: str, file_attributes: List[
105
105
return conf
106
106
107
107
108
- URIS = ["issuer" , "base_url" ]
109
-
110
-
111
108
def set_domain_and_port (conf : dict , uris : List [str ], domain : str , port : int ):
112
109
for key , val in conf .items ():
113
110
if key in uris :
@@ -154,42 +151,59 @@ def create_from_config_file(
154
151
)
155
152
156
153
157
- class Base :
154
+ class Base ( dict ) :
158
155
""" Configuration base class """
159
156
160
157
parameter = {}
161
158
162
159
def __init__ (
163
160
self , conf : Dict , base_path : str = "" , file_attributes : Optional [List [str ]] = None ,
164
161
):
162
+ dict .__init__ (self )
163
+
165
164
if file_attributes is None :
166
165
file_attributes = DEFAULT_FILE_ATTRIBUTE_NAMES
167
166
168
167
if base_path and file_attributes :
169
168
# this adds a base path to all paths in the configuration
170
169
add_base_path (conf , base_path , file_attributes )
171
170
172
- def __getitem__ (self , item ):
173
- if item in self .__dict__ :
174
- return self .__dict__ [item ]
175
- else :
176
- raise KeyError
177
-
178
- def get (self , item , default = None ):
179
- return getattr (self , item , default )
171
+ def __getattr__ (self , item ):
172
+ return self [item ]
180
173
181
- def __contains__ (self , item ):
182
- return item in self .__dict__
174
+ def __setattr__ (self , key , value ):
175
+ if key in self :
176
+ raise KeyError ('{} has already been set' .format (key ))
177
+ super (Base , self ).__setitem__ (key , value )
183
178
184
- def items (self ):
185
- for key in self .__dict__ :
186
- if key .startswith ("__" ) and key .endswith ("__" ):
187
- continue
188
- yield key , getattr (self , key )
179
+ def __setitem__ (self , key , value ):
180
+ if key in self :
181
+ raise KeyError ('{} has already been set' .format (key ))
182
+ super (Base , self ).__setitem__ (key , value )
189
183
190
184
191
185
class EntityConfiguration (Base ):
192
186
default_config = AS_DEFAULT_CONFIG
187
+ uris = ["issuer" , "base_url" ]
188
+ parameter = {
189
+ "add_on" : None ,
190
+ "authz" : None ,
191
+ "authentication" : None ,
192
+ "base_url" : "" ,
193
+ "capabilities" : None ,
194
+ "claims_interface" : None ,
195
+ "cookie_handler" : None ,
196
+ "endpoint" : {},
197
+ "httpc_params" : {},
198
+ "issuer" : "" ,
199
+ "keys" : None ,
200
+ "session_key" : None ,
201
+ "template_dir" : None ,
202
+ "token_handler_args" : {},
203
+ "userinfo" : None ,
204
+ "password" : None ,
205
+ "salt" : None ,
206
+ }
193
207
194
208
def __init__ (
195
209
self ,
@@ -204,72 +218,64 @@ def __init__(
204
218
conf = copy .deepcopy (conf )
205
219
Base .__init__ (self , conf , base_path , file_attributes )
206
220
207
- self .add_on = None
208
- self .authz = None
209
- self .authentication = None
210
- self .base_url = ""
211
- self .capabilities = None
212
- self .claims_interface = None
213
- self .cookie_handler = None
214
- self .endpoint = {}
215
- self .httpc_params = {}
216
- self .issuer = ""
217
- self .keys = None
218
- self .template_dir = None
219
- self .token_handler_args = {}
220
- self .userinfo = None
221
- self .session_params = None
222
-
223
221
if file_attributes is None :
224
222
file_attributes = DEFAULT_FILE_ATTRIBUTE_NAMES
225
223
226
- for key in self .__dict__ .keys ():
224
+ if not domain :
225
+ domain = conf .get ("domain" , "127.0.0.1" )
226
+
227
+ if not port :
228
+ port = conf .get ("port" , 80 )
229
+
230
+ for key in self .parameter .keys ():
227
231
_val = conf .get (key )
228
232
if not _val :
229
233
if key in self .default_config :
230
- _dc = copy .deepcopy (self .default_config [key ])
231
- add_base_path ( _dc , base_path , file_attributes )
232
- _val = _dc
234
+ _val = copy .deepcopy (self .default_config [key ])
235
+ self . format ( _val , base_path = base_path , file_attributes = file_attributes ,
236
+ domain = domain , port = port )
233
237
else :
234
238
continue
235
- setattr (self , key , _val )
236
239
237
- if self .template_dir is None :
238
- self .template_dir = os .path .abspath ("templates" )
239
- else :
240
- self .template_dir = os .path .abspath (self .template_dir )
240
+ if key == "template_dir" :
241
+ _val = os .path .abspath (_val )
241
242
242
- if not domain :
243
- domain = conf .get ("domain" , "127.0.0.1" )
244
-
245
- if not port :
246
- port = conf .get ("port" , 80 )
243
+ setattr (self , key , _val )
247
244
248
- set_domain_and_port (conf , URIS , domain = domain , port = port )
245
+ # try:
246
+ # _dir = self.template_dir
247
+ # except AttributeError:
248
+ # self.template_dir = os.path.abspath("templates")
249
+ # else:
250
+ # self.template_dir =
251
+
252
+ def format (self , conf , base_path , file_attributes , domain , port ):
253
+ """
254
+ Formats parts of the configuration. That includes replacing the strings {domain} and {port}
255
+ with the used domain and port and making references to files and directories absolute
256
+ rather then relative. The formatting is done in place.
257
+
258
+ :param conf: The configuration part
259
+ :param base_path: The base path used to make file/directory refrences absolute
260
+ :param file_attributes: Attribute names that refer to files or directories.
261
+ :param domain: The domain name
262
+ :param port: The port used
263
+ """
264
+ add_base_path (conf , base_path , file_attributes )
265
+ if isinstance (conf , dict ):
266
+ set_domain_and_port (conf , self .uris , domain = domain , port = port )
249
267
250
268
251
269
class OPConfiguration (EntityConfiguration ):
252
270
"Provider configuration"
253
271
default_config = OP_DEFAULT_CONFIG
254
-
255
- def __init__ (
256
- self ,
257
- conf : Dict ,
258
- base_path : Optional [str ] = "" ,
259
- entity_conf : Optional [List [dict ]] = None ,
260
- domain : Optional [str ] = "" ,
261
- port : Optional [int ] = 0 ,
262
- file_attributes : Optional [List [str ]] = None ,
263
- ):
264
- # OP special
265
- self .id_token = None
266
- self .login_hint2acrs = {}
267
- self .login_hint_lookup = None
268
-
269
- EntityConfiguration .__init__ (self , conf = conf , base_path = base_path ,
270
- entity_conf = entity_conf , domain = domain , port = port ,
271
- file_attributes = file_attributes )
272
-
272
+ parameter = EntityConfiguration .parameter .copy ()
273
+ parameter .update ({
274
+ "id_token" : None ,
275
+ "login_hint2acrs" : {},
276
+ "login_hint_lookup" : None ,
277
+ "sub_func" : {}
278
+ })
273
279
274
280
class ASConfiguration (EntityConfiguration ):
275
281
"Authorization server configuration"
@@ -290,6 +296,7 @@ def __init__(
290
296
291
297
class Configuration (Base ):
292
298
"""Server Configuration"""
299
+ uris = ["issuer" , "base_url" ]
293
300
294
301
def __init__ (
295
302
self ,
@@ -316,7 +323,7 @@ def __init__(
316
323
if not port :
317
324
port = conf .get ("port" , 80 )
318
325
319
- set_domain_and_port (conf , URIS , domain = domain , port = port )
326
+ set_domain_and_port (conf , self . uris , domain = domain , port = port )
320
327
321
328
if entity_conf :
322
329
for econf in entity_conf :
@@ -496,7 +503,7 @@ def __init__(
496
503
},
497
504
},
498
505
},
499
- "httpc_params" : {"verify" : False },
506
+ "httpc_params" : {"verify" : False , "timeout" : 4 },
500
507
"issuer" : "https://{domain}:{port}" ,
501
508
"keys" : {
502
509
"private_path" : "private/jwks.json" ,
@@ -511,7 +518,8 @@ def __init__(
511
518
"login_hint2acrs" : {
512
519
"class" : "oidcop.login_hint.LoginHint2Acrs" ,
513
520
"kwargs" : {
514
- "scheme_map" : {"email" : ["urn:oasis:names:tc:SAML:2.0:ac:classes:InternetProtocolPassword" ]}
521
+ "scheme_map" : {
522
+ "email" : ["urn:oasis:names:tc:SAML:2.0:ac:classes:InternetProtocolPassword" ]}
515
523
},
516
524
},
517
525
"template_dir" : "templates" ,
0 commit comments