Skip to content

Commit 99385e4

Browse files
author
Roland Hedberg
committed
Merge pull request #79 from novapost/node_name_entity
Add node_name parameter loaded from config file
2 parents bcc1f4c + 39640c1 commit 99385e4

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/saml2/mdstore.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ def repack_cert(cert):
103103

104104

105105
class MetaData(object):
106-
def __init__(self, onts, attrc, metadata=""):
106+
def __init__(self, onts, attrc, metadata="", node_name=None, **kwargs):
107107
self.onts = onts
108108
self.attrc = attrc
109109
self.entity = {}
110110
self.metadata = metadata
111111
self.security = None
112+
self.node_name = node_name
112113

113114
def items(self):
114115
return self.entity.items()
@@ -371,8 +372,8 @@ class MetaDataFile(MetaData):
371372
Handles Metadata file on the same machine. The format of the file is
372373
the SAML Metadata format.
373374
"""
374-
def __init__(self, onts, attrc, filename, cert=None):
375-
MetaData.__init__(self, onts, attrc)
375+
def __init__(self, onts, attrc, filename, cert=None, **kwargs):
376+
MetaData.__init__(self, onts, attrc, **kwargs)
376377
self.filename = filename
377378
self.cert = cert
378379

@@ -382,8 +383,9 @@ def get_metadata_content(self):
382383
def load(self):
383384
_txt = self.get_metadata_content()
384385
if self.cert:
385-
node_name = "%s:%s" % (md.EntitiesDescriptor.c_namespace,
386-
md.EntitiesDescriptor.c_tag)
386+
node_name = self.node_name \
387+
or "%s:%s" % (md.EntitiesDescriptor.c_namespace,
388+
md.EntitiesDescriptor.c_tag)
387389

388390
if self.security.verify_signature(_txt,
389391
node_name=node_name,
@@ -400,8 +402,8 @@ class MetaDataLoader(MetaDataFile):
400402
Handles Metadata file loaded by a passed in function.
401403
The format of the file is the SAML Metadata format.
402404
"""
403-
def __init__(self, onts, attrc, loader_callable, cert=None):
404-
MetaData.__init__(self, onts, attrc)
405+
def __init__(self, onts, attrc, loader_callable, cert=None, **kwargs):
406+
MetaData.__init__(self, onts, attrc, **kwargs)
405407
self.metadata_provider_callable = self.get_metadata_loader(loader_callable)
406408
self.cert = cert
407409

@@ -444,7 +446,7 @@ class MetaDataExtern(MetaData):
444446
Accessible but HTTP GET.
445447
"""
446448

447-
def __init__(self, onts, attrc, url, security, cert, http):
449+
def __init__(self, onts, attrc, url, security, cert, http, **kwargs):
448450
"""
449451
:params onts:
450452
:params attrc:
@@ -453,7 +455,7 @@ def __init__(self, onts, attrc, url, security, cert, http):
453455
:params cert:
454456
:params http:
455457
"""
456-
MetaData.__init__(self, onts, attrc)
458+
MetaData.__init__(self, onts, attrc, **kwargs)
457459
self.url = url
458460
self.security = security
459461
self.cert = cert
@@ -466,8 +468,9 @@ def load(self):
466468
"""
467469
response = self.http.send(self.url)
468470
if response.status_code == 200:
469-
node_name = "%s:%s" % (md.EntitiesDescriptor.c_namespace,
470-
md.EntitiesDescriptor.c_tag)
471+
node_name = self.node_name \
472+
or "%s:%s" % (md.EntitiesDescriptor.c_namespace,
473+
md.EntitiesDescriptor.c_tag)
471474

472475
_txt = response.text.encode("utf-8")
473476
if self.cert:
@@ -489,8 +492,8 @@ class MetaDataMD(MetaData):
489492
Handles locally stored metadata, the file format is the text representation
490493
of the Python representation of the metadata.
491494
"""
492-
def __init__(self, onts, attrc, filename):
493-
MetaData.__init__(self, onts, attrc)
495+
def __init__(self, onts, attrc, filenamen, **kwargs):
496+
MetaData.__init__(self, onts, attrc, **kwargs)
494497
self.filename = filename
495498

496499
def load(self):
@@ -523,12 +526,13 @@ def load(self, typ, *args, **kwargs):
523526
elif typ == "inline":
524527
self.ii += 1
525528
key = self.ii
526-
md = MetaData(self.onts, self.attrc, args[0])
529+
md = MetaData(self.onts, self.attrc, args[0], **kwargs)
527530
elif typ == "remote":
528531
key = kwargs["url"]
529532
md = MetaDataExtern(self.onts, self.attrc,
530533
kwargs["url"], self.security,
531-
kwargs["cert"], self.http)
534+
kwargs["cert"], self.http,
535+
node_name=kwargs.get('node_name'))
532536
elif typ == "mdfile":
533537
key = args[0]
534538
md = MetaDataMD(self.onts, self.attrc, args[0])

0 commit comments

Comments
 (0)