Skip to content

Commit d03c2a1

Browse files
committed
If a Configure class has no parameters defined it should store all expect those that are referenced as entity type specific.
1 parent d05f587 commit d03c2a1

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/idpyoidc/configure.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Dict
44
from typing import List
55
from typing import Optional
6+
from typing import Union
67

78
from idpyoidc.logging import configure_logging
89
from idpyoidc.util import load_config_file
@@ -38,6 +39,9 @@ def add_path_to_directory_name(directory_name, base_path):
3839

3940
def add_base_path(conf: dict, base_path: str, attributes: List[str], attribute_type: str = "file"):
4041
for key, val in conf.items():
42+
if not val:
43+
continue
44+
4145
if key in attributes:
4246
if attribute_type == "file":
4347
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
168172

169173
def format(self, conf, base_path: str, domain: str, port: int,
170174
file_attributes: Optional[List[str]] = None,
171-
dir_attributes: Optional[List[str]] = None) -> None:
175+
dir_attributes: Optional[List[str]] = None) -> Union[Dict, str]:
172176
"""
173177
Formats parts of the configuration. That includes replacing the strings {domain} and {port}
174178
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,
183187
"""
184188
if isinstance(conf, dict):
185189
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")
187191
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")
189193
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
191201

192202

193203
class Configuration(Base):
@@ -215,10 +225,20 @@ def __init__(self,
215225
self.web_conf = lower_or_upper(self.conf, "webserver")
216226

217227
if entity_conf:
228+
skip = [ec["path"] for ec in entity_conf]
229+
218230
self.extend(conf=self.conf, base_path=base_path,
219231
domain=self.domain, port=self.port, entity_conf=entity_conf,
220232
file_attributes=self._file_attributes,
221233
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)
222242

223243

224244
def create_from_config_file(cls,

src/idpyoidc/server/configure.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,17 @@ def __init__(
168168
):
169169

170170
conf = copy.deepcopy(conf)
171-
Base.__init__(self, conf, base_path, file_attributes, dir_attributes=dir_attributes)
171+
Base.__init__(self, conf, base_path, file_attributes=file_attributes,
172+
dir_attributes=dir_attributes, domain=domain, port=port)
172173

173174
self.key_conf = conf.get('key_conf')
174175

175176
for key in self.parameter.keys():
176177
_val = conf.get(key)
177178
if not _val:
178179
if key in self.default_config:
179-
_val = copy.deepcopy(self.default_config[key])
180-
self.format(
181-
_val,
180+
_val = self.format(
181+
copy.deepcopy(self.default_config[key]),
182182
base_path=base_path,
183183
file_attributes=file_attributes,
184184
domain=domain,
@@ -466,7 +466,9 @@ def __init__(
466466
"jwks_def": {
467467
"private_path": "private/token_jwks.json",
468468
"read_only": False,
469-
"key_defs": [{"type": "oct", "bytes": "24", "use": ["enc"], "kid": "code"}],
469+
"key_defs": [
470+
{"type": "oct", "bytes": "24", "use": ["enc"], "kid": "code"}
471+
],
470472
},
471473
"code": {"kwargs": {"lifetime": 600}},
472474
"token": {

0 commit comments

Comments
 (0)