From d03c2a1a68cbb76596ac700fa32d8bd6e5d05d8c Mon Sep 17 00:00:00 2001 From: Roland Hedberg Date: Wed, 30 Mar 2022 15:49:59 +0200 Subject: [PATCH] If a Configure class has no parameters defined it should store all expect those that are referenced as entity type specific. --- src/idpyoidc/configure.py | 28 ++++++++++++++++++++++++---- src/idpyoidc/server/configure.py | 12 +++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/idpyoidc/configure.py b/src/idpyoidc/configure.py index 222146d6..62500826 100644 --- a/src/idpyoidc/configure.py +++ b/src/idpyoidc/configure.py @@ -3,6 +3,7 @@ from typing import Dict from typing import List from typing import Optional +from typing import Union from idpyoidc.logging import configure_logging from idpyoidc.util import load_config_file @@ -38,6 +39,9 @@ def add_path_to_directory_name(directory_name, base_path): def add_base_path(conf: dict, base_path: str, attributes: List[str], attribute_type: str = "file"): for key, val in conf.items(): + if not val: + continue + if key in attributes: if attribute_type == "file": 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 def format(self, conf, base_path: str, domain: str, port: int, file_attributes: Optional[List[str]] = None, - dir_attributes: Optional[List[str]] = None) -> None: + dir_attributes: Optional[List[str]] = None) -> Union[Dict, str]: """ Formats parts of the configuration. That includes replacing the strings {domain} and {port} 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, """ if isinstance(conf, dict): if file_attributes: - add_base_path(conf, base_path, file_attributes, attribute_type="file") + conf = add_base_path(conf, base_path, file_attributes, attribute_type="file") if dir_attributes: - add_base_path(conf, base_path, dir_attributes, attribute_type="dir") + conf = add_base_path(conf, base_path, dir_attributes, attribute_type="dir") if isinstance(conf, dict): - set_domain_and_port(conf, domain=domain, port=port) + conf = set_domain_and_port(conf, domain=domain, port=port) + elif isinstance(conf, list): + conf = [_conv(v, domain=domain, port=port) for v in conf] + elif isinstance(conf, str): + conf = _conv(conf, domain, port) + + return conf class Configuration(Base): @@ -215,10 +225,20 @@ def __init__(self, self.web_conf = lower_or_upper(self.conf, "webserver") if entity_conf: + skip = [ec["path"] for ec in entity_conf] + self.extend(conf=self.conf, base_path=base_path, domain=self.domain, port=self.port, entity_conf=entity_conf, file_attributes=self._file_attributes, dir_attributes=self._dir_attributes) + for key, val in conf.items(): + for path in skip: + if key == path[0]: + continue + setattr(self, key, val) + else: + for key, val in conf.items(): + setattr(self, key, val) def create_from_config_file(cls, diff --git a/src/idpyoidc/server/configure.py b/src/idpyoidc/server/configure.py index d3cfbace..3dfb1928 100755 --- a/src/idpyoidc/server/configure.py +++ b/src/idpyoidc/server/configure.py @@ -168,7 +168,8 @@ def __init__( ): conf = copy.deepcopy(conf) - Base.__init__(self, conf, base_path, file_attributes, dir_attributes=dir_attributes) + Base.__init__(self, conf, base_path, file_attributes=file_attributes, + dir_attributes=dir_attributes, domain=domain, port=port) self.key_conf = conf.get('key_conf') @@ -176,9 +177,8 @@ def __init__( _val = conf.get(key) if not _val: if key in self.default_config: - _val = copy.deepcopy(self.default_config[key]) - self.format( - _val, + _val = self.format( + copy.deepcopy(self.default_config[key]), base_path=base_path, file_attributes=file_attributes, domain=domain, @@ -466,7 +466,9 @@ def __init__( "jwks_def": { "private_path": "private/token_jwks.json", "read_only": False, - "key_defs": [{"type": "oct", "bytes": "24", "use": ["enc"], "kid": "code"}], + "key_defs": [ + {"type": "oct", "bytes": "24", "use": ["enc"], "kid": "code"} + ], }, "code": {"kwargs": {"lifetime": 600}}, "token": {