summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEgor Panfilov <edpanfilov@sbcloud.ru>2018-11-19 18:08:37 +0300
committerEgor Panfilov <edpanfilov@sbcloud.ru>2018-11-19 18:08:37 +0300
commitc79c50ad18aea97fa29f63700410e433efa2f1cc (patch)
tree39e3109a142a68afbd1cc8924d60b7530016372e /src
parentc07b12e208d6246b2d6219635884c184f1c11649 (diff)
downloadpysaml2-c79c50ad18aea97fa29f63700410e433efa2f1cc.tar.gz
Make config_factory more universal method
Diffstat (limited to 'src')
-rw-r--r--src/saml2/config.py34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/saml2/config.py b/src/saml2/config.py
index 8f90afc8..0541a8be 100644
--- a/src/saml2/config.py
+++ b/src/saml2/config.py
@@ -563,14 +563,30 @@ class IdPConfig(Config):
Config.__init__(self)
-def config_factory(typ, filename):
- if typ == "sp":
- conf = SPConfig().load_file(filename)
- conf.context = typ
- elif typ in ["aa", "idp", "pdp", "aq"]:
- conf = IdPConfig().load_file(filename)
- conf.context = typ
+def config_factory(_type, config):
+ """
+
+ :type _type: str
+ :param _type:
+
+ :type config: str or dict
+ :param config: Name of file with pysaml2 config or CONFIG dict
+
+ :return:
+ """
+ if _type == "sp":
+ conf = SPConfig()
+ elif _type in ["aa", "idp", "pdp", "aq"]:
+ conf = IdPConfig()
else:
- conf = Config().load_file(filename)
- conf.context = typ
+ conf = Config()
+
+ if isinstance(config, dict):
+ conf.load(copy.deepcopy(config))
+ elif isinstance(config, str):
+ conf.load_file(config)
+ else:
+ raise ValueError('Unknown type of config')
+
+ conf.context = _type
return conf