|
2 | 2 |
|
3 | 3 | import os |
4 | 4 | from typing import Dict |
| 5 | +from typing import Optional |
5 | 6 |
|
6 | 7 | from cryptojwt.key_bundle import init_key |
| 8 | +from oidcmsg import add_base_path |
7 | 9 |
|
8 | 10 | from oidcop.logging import configure_logging |
9 | 11 | from oidcop.utils import load_yaml_config |
|
13 | 15 | except ImportError: |
14 | 16 | from oidcendpoint import rndstr as rnd_token |
15 | 17 |
|
| 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 | + |
16 | 38 |
|
17 | 39 | class Configuration: |
18 | 40 | """OP Configuration""" |
19 | 41 |
|
20 | | - def __init__(self, conf: Dict) -> None: |
| 42 | + def __init__(self, conf: Dict, base_path: str = '', item_paths: Optional[dict] = None) -> None: |
21 | 43 | 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) |
23 | 51 |
|
24 | 52 | # OIDC provider configuration |
25 | 53 | for section in ['op', 'webserver', 'httpc_params', 'jinja_env']: |
@@ -47,6 +75,7 @@ def __init__(self, conf: Dict) -> None: |
47 | 75 | setattr(self, param, _pre) |
48 | 76 |
|
49 | 77 | @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): |
51 | 80 | """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