Skip to content

Commit

Permalink
If a Configure class has no parameters defined it should store all ex…
Browse files Browse the repository at this point in the history
…pect those that are referenced as entity type specific.
  • Loading branch information
rohe committed Mar 30, 2022
1 parent d05f587 commit d03c2a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
28 changes: 24 additions & 4 deletions src/idpyoidc/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions src/idpyoidc/server/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,17 @@ 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')

for key in self.parameter.keys():
_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,
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit d03c2a1

Please sign in to comment.