Skip to content

Commit

Permalink
Merge pull request #855 from REANNZ/fix/reload-inplace
Browse files Browse the repository at this point in the history
Reload metadata in-place
  • Loading branch information
c00kiemon5ter authored Mar 4, 2022
2 parents 31cd74c + bf0a4e6 commit bf6298c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/saml2/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,11 @@ def reload_metadata(self, metadata_conf):
"""
logger.debug("Loading new metadata")
try:
new_metadata = self.config.load_metadata(metadata_conf)
self.metadata.reload(metadata_conf)
except Exception as ex:
logger.error("Loading metadata failed", exc_info=ex)
return False

logger.debug("Applying new metadata to main config")
( self.metadata, self.sec.metadata, self.config.metadata ) = [new_metadata]*3
policy = getattr(self.config, "_%s_policy" % self.entity_type, None)
if policy and policy.metadata_store:
logger.debug("Applying new metadata to %s policy", self.entity_type)
policy.metadata_store = self.metadata

logger.debug("Applying new metadata source_id")
self.sourceid = self.metadata.construct_source_id()

return True
Expand Down
12 changes: 12 additions & 0 deletions src/saml2/mdstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,18 @@ def load(self, *args, **kwargs):
_md.load()
self.metadata[key] = _md

def reload(self, spec):
# Save the old set of metadata
old_metadata = self.metadata
self.metadata = {}
try:
# Reload the metadata based on the spec
self.imp(spec)
except Exception as e:
# Something went wrong, restore the previous metadata
self.metadata = old_metadata
raise e

def imp(self, spec):
# This serves as a backwards compatibility
if type(spec) is dict:
Expand Down

0 comments on commit bf6298c

Please sign in to comment.