33import json
44import logging
55import os
6+ from typing import Any
67from typing import Dict
78from typing import List
89from typing import Optional
910
1011from oidcrp .logging import configure_logging
1112from oidcrp .util import load_yaml_config
1213from oidcrp .util import lower_or_upper
13- from oidcrp .util import replace
1414
1515try :
1616 from secrets import token_urlsafe as rnd_token
@@ -87,6 +87,7 @@ class RPConfiguration(Base):
8787 def __init__ (self ,
8888 conf : Dict ,
8989 base_path : Optional [str ] = '' ,
90+ entity_conf : Optional [List [dict ]] = None ,
9091 domain : Optional [str ] = "127.0.0.1" ,
9192 port : Optional [int ] = 80 ,
9293 file_attributes : Optional [List [str ]] = None ,
@@ -100,19 +101,14 @@ def __init__(self,
100101
101102 self .keys = _keys_conf
102103
104+ if not domain :
105+ domain = conf .get ("domain" , "127.0.0.1" )
106+
107+ if not port :
108+ port = conf .get ("port" , 80 )
109+
103110 conf = set_domain_and_port (conf , URIS , domain , port )
104111 self .clients = lower_or_upper (conf , "clients" )
105- # if _clients:
106- # format_args = {"domain": domain, "port": port}
107- # for key, spec in _clients.items():
108- # if key == "":
109- # continue
110- #
111- # for uri in ['redirect_uris', 'post_logout_redirect_uris', 'frontchannel_logout_uri',
112- # 'backchannel_logout_uri', 'issuer']:
113- # replace(spec, uri, **format_args)
114- #
115- # self.clients = _clients
116112
117113 hash_seed = lower_or_upper (conf , 'hash_seed' )
118114 if not hash_seed :
@@ -129,13 +125,13 @@ class Configuration(Base):
129125
130126 def __init__ (self ,
131127 conf : Dict ,
132- entity_conf_class ,
133128 base_path : str = '' ,
129+ entity_conf : Optional [List [dict ]] = None ,
134130 file_attributes : Optional [List [str ]] = None ,
135131 domain : Optional [str ] = "" ,
136132 port : Optional [int ] = 0 ,
137133 ):
138- Base .__init__ (self , conf , base_path , file_attributes )
134+ Base .__init__ (self , conf , base_path = base_path , file_attributes = file_attributes )
139135
140136 log_conf = conf .get ('logging' )
141137 if log_conf :
@@ -152,37 +148,42 @@ def __init__(self,
152148 if not port :
153149 port = conf .get ("port" , 80 )
154150
155- self .rp = entity_conf_class (conf , base_path = base_path , file_attributes = file_attributes ,
156- domain = domain , port = port )
151+ if entity_conf :
152+ for econf in entity_conf :
153+ _path = econf .get ("path" )
154+ _cnf = conf
155+ if _path :
156+ for step in _path :
157+ _cnf = _cnf [step ]
158+ _attr = econf ["attr" ]
159+ _cls = econf ["class" ]
160+ setattr (self , _attr ,
161+ _cls (_cnf , base_path = base_path , file_attributes = file_attributes ,
162+ domain = domain , port = port ))
157163
158164
159165def create_from_config_file (cls ,
160- entity_conf_class ,
161166 filename : str ,
162- base_path : str = '' ,
167+ base_path : Optional [str ] = '' ,
168+ entity_conf : Optional [List [dict ]] = None ,
163169 file_attributes : Optional [List [str ]] = None ,
164170 domain : Optional [str ] = "" ,
165171 port : Optional [int ] = 0 ):
166172 if filename .endswith (".yaml" ):
167173 """Load configuration as YAML"""
168- return cls (load_yaml_config (filename ),
169- entity_conf_class = entity_conf_class ,
170- base_path = base_path , file_attributes = file_attributes ,
171- domain = domain , port = port )
174+ _cnf = load_yaml_config (filename )
172175 elif filename .endswith (".json" ):
173176 _str = open (filename ).read ()
174- return cls (json .loads (_str ),
175- entity_conf_class = entity_conf_class ,
176- base_path = base_path , file_attributes = file_attributes , domain = domain , port = port )
177+ _cnf = json .loads (_str )
177178 elif filename .endswith (".py" ):
178179 head , tail = os .path .split (filename )
179180 tail = tail [:- 3 ]
180181 module = importlib .import_module (tail )
181182 _cnf = getattr (module , "CONFIG" )
183+ else :
184+ raise ValueError ("Unknown file type" )
182185
183- # _str = open(filename).read()
184- # _cnf = ast.literal_eval(_str)
185- return cls (_cnf ,
186- entity_conf_class = entity_conf_class ,
187- base_path = base_path , file_attributes = file_attributes ,
188- domain = domain , port = port )
186+ return cls (_cnf ,
187+ entity_conf = entity_conf ,
188+ base_path = base_path , file_attributes = file_attributes ,
189+ domain = domain , port = port )
0 commit comments