Skip to content

Commit c3d6209

Browse files
Merge pull request #562 from erakli/update_config_factory
Make config_factory to be more universal method
2 parents 194f5ff + c79c50a commit c3d6209

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/saml2/config.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,30 @@ def __init__(self):
563563
Config.__init__(self)
564564

565565

566-
def config_factory(typ, filename):
567-
if typ == "sp":
568-
conf = SPConfig().load_file(filename)
569-
conf.context = typ
570-
elif typ in ["aa", "idp", "pdp", "aq"]:
571-
conf = IdPConfig().load_file(filename)
572-
conf.context = typ
566+
def config_factory(_type, config):
567+
"""
568+
569+
:type _type: str
570+
:param _type:
571+
572+
:type config: str or dict
573+
:param config: Name of file with pysaml2 config or CONFIG dict
574+
575+
:return:
576+
"""
577+
if _type == "sp":
578+
conf = SPConfig()
579+
elif _type in ["aa", "idp", "pdp", "aq"]:
580+
conf = IdPConfig()
573581
else:
574-
conf = Config().load_file(filename)
575-
conf.context = typ
582+
conf = Config()
583+
584+
if isinstance(config, dict):
585+
conf.load(copy.deepcopy(config))
586+
elif isinstance(config, str):
587+
conf.load_file(config)
588+
else:
589+
raise ValueError('Unknown type of config')
590+
591+
conf.context = _type
576592
return conf

0 commit comments

Comments
 (0)