Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
docstrings and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Sep 24, 2019
1 parent 284e1cb commit a25b66d
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions synapse/config/saml2_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,32 @@
from ._base import Config, ConfigError


def _dict_merge(merge_dict, into_dct):
def _dict_merge(merge_dict, into_dict):
"""Do a deep merge of two dicts
Recursively merges `merge_dict` into `into_dict`:
* For keys where both `merge_dict` and `into_dict` have a dict value, the values
are recursively merged
* For all other keys, the values in `into_dict` (if any) are overwritten with
the value from `merge_dict`.
Args:
merge_dict (dict): dict to merge
into_dict (dict): target dict
"""
for k, v in merge_dict.items():
if k not in into_dct:
into_dct[k] = v
if k not in into_dict:
into_dict[k] = v
continue

current_val = into_dct[k]
current_val = into_dict[k]

if isinstance(v, dict) and isinstance(current_val, dict):
_dict_merge(v, current_val)
continue

# otherwise we just overwrite
into_dct[k] = v
into_dict[k] = v


class SAML2Config(Config):
Expand All @@ -53,12 +65,14 @@ def read_config(self, config, **kwargs):
self.saml2_enabled = True

saml2_config_dict = self._default_saml_config_dict()
_dict_merge(saml2_config.get("sp_config", {}), saml2_config_dict)
_dict_merge(
merge_dict=saml2_config.get("sp_config", {}), into_dict=saml2_config_dict
)

config_path = saml2_config.get("config_path", None)
if config_path is not None:
mod = load_python_module(config_path)
_dict_merge(mod.CONFIG, saml2_config_dict)
_dict_merge(merge_dict=mod.CONFIG, into_dict=saml2_config_dict)

import saml2.config

Expand Down

0 comments on commit a25b66d

Please sign in to comment.