3
3
from typing import Dict
4
4
from typing import List
5
5
from typing import Optional
6
+ from typing import Union
6
7
7
8
from idpyoidc .logging import configure_logging
8
9
from idpyoidc .util import load_config_file
@@ -38,6 +39,9 @@ def add_path_to_directory_name(directory_name, base_path):
38
39
39
40
def add_base_path (conf : dict , base_path : str , attributes : List [str ], attribute_type : str = "file" ):
40
41
for key , val in conf .items ():
42
+ if not val :
43
+ continue
44
+
41
45
if key in attributes :
42
46
if attribute_type == "file" :
43
47
conf [key ] = add_path_to_filename (val , base_path )
@@ -168,7 +172,7 @@ def complete_paths(self, conf: Dict, keys: List[str], default_config: Dict, base
168
172
169
173
def format (self , conf , base_path : str , domain : str , port : int ,
170
174
file_attributes : Optional [List [str ]] = None ,
171
- dir_attributes : Optional [List [str ]] = None ) -> None :
175
+ dir_attributes : Optional [List [str ]] = None ) -> Union [ Dict , str ] :
172
176
"""
173
177
Formats parts of the configuration. That includes replacing the strings {domain} and {port}
174
178
with the used domain and port and making references to files and directories absolute
@@ -183,11 +187,17 @@ def format(self, conf, base_path: str, domain: str, port: int,
183
187
"""
184
188
if isinstance (conf , dict ):
185
189
if file_attributes :
186
- add_base_path (conf , base_path , file_attributes , attribute_type = "file" )
190
+ conf = add_base_path (conf , base_path , file_attributes , attribute_type = "file" )
187
191
if dir_attributes :
188
- add_base_path (conf , base_path , dir_attributes , attribute_type = "dir" )
192
+ conf = add_base_path (conf , base_path , dir_attributes , attribute_type = "dir" )
189
193
if isinstance (conf , dict ):
190
- set_domain_and_port (conf , domain = domain , port = port )
194
+ conf = set_domain_and_port (conf , domain = domain , port = port )
195
+ elif isinstance (conf , list ):
196
+ conf = [_conv (v , domain = domain , port = port ) for v in conf ]
197
+ elif isinstance (conf , str ):
198
+ conf = _conv (conf , domain , port )
199
+
200
+ return conf
191
201
192
202
193
203
class Configuration (Base ):
@@ -215,10 +225,20 @@ def __init__(self,
215
225
self .web_conf = lower_or_upper (self .conf , "webserver" )
216
226
217
227
if entity_conf :
228
+ skip = [ec ["path" ] for ec in entity_conf ]
229
+
218
230
self .extend (conf = self .conf , base_path = base_path ,
219
231
domain = self .domain , port = self .port , entity_conf = entity_conf ,
220
232
file_attributes = self ._file_attributes ,
221
233
dir_attributes = self ._dir_attributes )
234
+ for key , val in conf .items ():
235
+ for path in skip :
236
+ if key == path [0 ]:
237
+ continue
238
+ setattr (self , key , val )
239
+ else :
240
+ for key , val in conf .items ():
241
+ setattr (self , key , val )
222
242
223
243
224
244
def create_from_config_file (cls ,
0 commit comments