Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 5d9701d

Browse files
committed
Allow relative paths in configuration to be made absolute.
1 parent 5f286d8 commit 5d9701d

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

src/oidcop/configure.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import os
44
from typing import Dict
5+
from typing import Optional
56

67
from cryptojwt.key_bundle import init_key
8+
from oidcmsg import add_base_path
79

810
from oidcop.logging import configure_logging
911
from oidcop.utils import load_yaml_config
@@ -13,13 +15,39 @@
1315
except ImportError:
1416
from oidcendpoint import rndstr as rnd_token
1517

18+
DEFAULT_ITEM_PATHS = {
19+
"webserver": ['server_key', 'server_cert'],
20+
"op": {
21+
"server_info": {
22+
"session_key": ["filename"],
23+
"template_dir": None,
24+
"token_handler_args": {
25+
"jwks_def": ["private_path", "public_path"]
26+
},
27+
"keys": ["private_path", "public_path"],
28+
"cookie_dealer": {
29+
"kwargs": {
30+
"sign_jwk": ["private_path", "public_path"],
31+
"enc_jwk": ["private_path", "public_path"]
32+
}
33+
}
34+
}
35+
}
36+
}
37+
1638

1739
class Configuration:
1840
"""OP Configuration"""
1941

20-
def __init__(self, conf: Dict) -> None:
42+
def __init__(self, conf: Dict, base_path: str = '', item_paths: Optional[dict] = None) -> None:
2143
self.logger = configure_logging(config=conf.get('logging')).getChild(__name__)
22-
self.op = None
44+
self.op = {}
45+
if item_paths is None:
46+
item_paths = DEFAULT_ITEM_PATHS
47+
48+
if base_path and item_paths:
49+
# this adds a base path to all paths in the configuration
50+
add_base_path(conf, item_paths, base_path)
2351

2452
# OIDC provider configuration
2553
for section in ['op', 'webserver', 'httpc_params', 'jinja_env']:
@@ -47,6 +75,7 @@ def __init__(self, conf: Dict) -> None:
4775
setattr(self, param, _pre)
4876

4977
@classmethod
50-
def create_from_config_file(cls, filename: str):
78+
def create_from_config_file(cls, filename: str, base_path: str = '',
79+
item_paths: Optional[dict] = None):
5180
"""Load configuration as YAML"""
52-
return cls(load_yaml_config(filename))
81+
return cls(load_yaml_config(filename), base_path, item_paths)

0 commit comments

Comments
 (0)