11"""Configuration management for RP"""
2-
2+ import os
33from typing import Dict
4+ from typing import Optional
5+
6+ from oidcmsg import add_base_path
47
58from oidcrp .logging import configure_logging
69from oidcrp .util import get_http_params
1518 from oidcendpoint import rndstr as rnd_token
1619
1720
21+ DEFAULT_ITEM_PATHS = {
22+ "webserver" : ['server_key' , 'server_cert' ],
23+ "rp_keys" : ["public_path" , "private_path" ],
24+ "oidc_keys" : ["public_path" , "private_path" ],
25+ "httpc_params" : ["client_cert" , "client_key" ],
26+ "db_conf" : {
27+ "keyjar" : ["fdir" ],
28+ "default" : ["fdir" ],
29+ "state" : ["fdir" ]
30+ },
31+ "logging" : {
32+ "handlers" : {
33+ "file" : ["filename" ]
34+ }
35+ }
36+ }
37+
38+
1839class Configuration :
1940 """RP Configuration"""
2041
21- def __init__ (self , conf : Dict ) -> None :
42+ def __init__ (self , conf : Dict , base_path : str = '' , item_paths : Optional [dict ] = None ) -> None :
43+ if item_paths is None :
44+ item_paths = DEFAULT_ITEM_PATHS
45+
46+ if base_path and item_paths :
47+ # this adds a base path to all paths in the configuration
48+ add_base_path (conf , item_paths , base_path )
49+
2250 self .logger = configure_logging (config = conf .get ('logging' )).getChild (__name__ )
2351
2452 # server info
@@ -49,6 +77,7 @@ def __init__(self, conf: Dict) -> None:
4977 rp_keys_conf = lower_or_upper (conf , 'rp_keys' )
5078 if rp_keys_conf is None :
5179 rp_keys_conf = lower_or_upper (conf , 'oidc_keys' )
80+
5281 setattr (self , "rp_keys" , rp_keys_conf )
5382
5483 _clients = lower_or_upper (conf , "clients" )
@@ -75,6 +104,6 @@ def load_extension(self, conf):
75104 pass
76105
77106 @classmethod
78- def create_from_config_file (cls , filename : str ):
107+ def create_from_config_file (cls , filename : str , base_path : str = '' ):
79108 """Load configuration as YAML"""
80- return cls (load_yaml_config (filename ))
109+ return cls (load_yaml_config (filename ), base_path )
0 commit comments