Skip to content

Commit

Permalink
Store Metadata in Mongo DB.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland Hedberg committed Apr 19, 2013
1 parent a92e4b6 commit 3c5dd5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
16 changes: 8 additions & 8 deletions src/saml2/mdstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _service(self, entity_id, typ, service, binding=None):
binding))
try:
srvs = []
for t in self.entity[entity_id][typ]:
for t in self[entity_id][typ]:
try:
srvs.extend(t[service])
except KeyError:
Expand Down Expand Up @@ -223,7 +223,7 @@ def _service(self, entity_id, typ, service, binding=None):

def _ext_service(self, entity_id, typ, service, binding):
try:
srvs = self.entity[entity_id][typ]
srvs = self[entity_id][typ]
except KeyError:
return None

Expand All @@ -250,7 +250,7 @@ def any(self, typ, service, binding=None):
:return:
"""
res = {}
for ent in self.entity.keys():
for ent in self.keys():
bind = self._service(ent, typ, service, binding)
if bind:
res[ent] = bind
Expand Down Expand Up @@ -280,7 +280,7 @@ def attribute_requirement(self, entity_id, index=0):
res = {"required": [], "optional": []}

try:
for sp in self.entity[entity_id]["spsso_descriptor"]:
for sp in self[entity_id]["spsso_descriptor"]:
_res = attribute_requirement(sp)
res["required"].extend(_res["required"])
res["optional"].extend(_res["optional"])
Expand All @@ -290,22 +290,22 @@ def attribute_requirement(self, entity_id, index=0):
return res

def dumps(self):
return json.dumps(self.entity, indent=2)
return json.dumps(self.items(), indent=2)

def with_descriptor(self, descriptor):
res = {}
desc = "%s_descriptor" % descriptor
for eid, ent in self.entity.items():
for eid, ent in self.items():
if desc in ent:
res[eid] = ent
return res

def __str__(self):
return "%s" % (self.entity,)
return "%s" % self.items()

def construct_source_id(self):
res = {}
for eid, ent in self.entity.items():
for eid, ent in self.items():
for desc in ["spsso_descriptor", "idpsso_descriptor"]:
try:
for srv in ent[desc]:
Expand Down
36 changes: 23 additions & 13 deletions src/saml2/mongo_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pymongo import MongoClient
from saml2.eptid import Eptid
from saml2.mdstore import MetaData
from saml2.mdstore import MetaData, attribute_requirement
from saml2.s_utils import PolicyError

from saml2.ident import code, IdentDB, Unknown
Expand Down Expand Up @@ -249,7 +249,6 @@ def __contains__(self, key):

#------------------------------------------------------------------------------
class EptidMDB(Eptid):

def __init__(self, secret, collection="", sub_collection="eptid"):
Eptid.__init__(self, secret)
self.mdb = MDB(collection, sub_collection)
Expand All @@ -269,6 +268,16 @@ def __setitem__(self, key, value):


#------------------------------------------------------------------------------
def export_mdstore_to_mongo_db(mds, onts, collection, sub_collection=""):
mdb = MDB(collection, sub_collection)
mdb.primary_key = "entity_id"
for key, desc in mds.items():
kwargs = {
"entity_description": to_dict(desc, onts.values(), True),
}
mdb.store(key, **kwargs)


class MetadataMDB(MetaData):
def __init__(self, onts, attrc, collection="", sub_collection=""):
MetaData.__init__(self, onts, attrc)
Expand All @@ -291,7 +300,7 @@ def _service(self, entity_id, typ, service, binding=None):

def _ext_service(self, entity_id, typ, service, binding):
try:
srvs = self.entity[entity_id][typ]
srvs = self[entity_id][typ]
except KeyError:
return None

Expand All @@ -312,22 +321,23 @@ def load(self):
pass

def items(self):
return self.mdb.items()
for key, item in self.mdb.items():
yield key, from_dict(item["entity_description"], self.onts, True)

def keys(self):
return self.mdb.keys()

def __contains__(self, item):
pass

def attribute_requirement(self):
pass
return item in self.mdb

def with_descriptor(self):
pass

def construct_source_id(self):
pass
def __getitem__(self, item):
res = self.mdb.get(item)
if not res:
raise KeyError(item)
elif len(res) == 1:
return from_dict(res[0]["entity_description"], self.onts, True)
else:
raise CorruptDatabase("More then one document with key %s" % item)

def bindings(self, entity_id, typ, service):
pass

0 comments on commit 3c5dd5a

Please sign in to comment.