def handle(self, replacement_rd3): # assign doc_id if need. ResourceDataModelValidator.assign_id(replacement_rd3) # validate the rd3 to be published. ResourceDataModelValidator.validate_model(replacement_rd3) # check to see if it's a replacement if replacement_rd3 is not None and _REPLACES in replacement_rd3: replacement_rd3_info = get_verification_info(replacement_rd3) if replacement_rd3_info is not None: graveyard = [] existing_gravestones = [] for orig_doc_id in replacement_rd3[_REPLACES]: try: orig_doc = self.db[orig_doc_id] orig_doc_info = get_verification_info(orig_doc) except couchdb.http.ResourceNotFound as rne: orig_doc = None orig_doc_info = None if orig_doc is not None and orig_doc["doc_type"] == "tombstone": permitted = True existing_gravestones.append(orig_doc) else: # verify that tombstones permitted = self._check_if_permitted(replacement_rd3, replacement_rd3_info, orig_doc, orig_doc_info) log.debug("handle: permitted? {0}".format(permitted)) if permitted: tombstone = self._make_tombstone(replacement_rd3, replacement_rd3_info, orig_doc_id, orig_doc) graveyard.append(tombstone) else: log.debug("Replacement resource not permitted to be saved.") # this should save unless a permit plugin has thrown an exception to disallow saving result = ResourceDataModelValidator.save(replacement_rd3, skip_validation=True) if self._has_graveyard_permit(replacement_rd3, replacement_rd3_info, graveyard, existing_gravestones): for tombstone in graveyard: try: self.db[tombstone["_id"]] = tombstone except: # if this is already a tombstone, then it's okay - first wins TombstoneValidator.validate_model(self.db[tombstone["_id"]]) # else: # # import pdb; pdb.set_trace() # raise SpecValidationException("Node policy does not permit this resource published.") return result # we get here because it's not a replacement. return ResourceDataModelValidator.save(replacement_rd3, skip_validation=True)
def test_fetchSelfHostedKey(*args, **kw): doc = { "doc_type": "resource_data", "replaces": ["804026fc367a4a44a76bd5b4c24809d8"], "update_timestamp": "2013-06-25T10:32:28.373753Z", "digital_signature": { "key_location": ["http://www.oercommons.org/public-key.txt"], "key_owner": "OER Commons <*****@*****.**>", "signing_method": "LR-PGP.1.0", "signature": "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA1\n\n47766650c7a3a81409e53161c918e9312994718e7d8d2a0c67ed6bb05d83566a\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.11 (Darwin)\nComment: GPGTools - http://gpgtools.org\n\niQEcBAEBAgAGBQJRyXG7AAoJEKPVkXeiZE8+R8UH/RVyspUdg1+iUiRG5+hIlsFl\ndgccEKubzTmps3G6vIOD7LEmObx23/dMhQiQByOvqLyjQkSv1E9E9NL/aOCGE7X4\nWUDaV5EheHKnnEP2q4w91qPuJ9GKU2XIE0n8wQVSLjFTju9Oc0IsFQMERbiew+WD\nwRwmc2SiaJBmLQ68fmEht07+R/fBw0aoHVl3lt+tz7VKao2A5+L3QHMQqwaILBdV\nJysFtSrrz3s2lopuuG4hRz+2rh/tPQwUWUS+kABg2s073Tt+fahHHekuG5ugamU8\nzzcNysozxFQACk4pbSGc7f/V8hxRFo6V5XxLjfgS06QfMFkdDFn7sbL3nB58oaA=\n=jBP2\n-----END PGP SIGNATURE-----\n" }, "TOS": { "submission_TOS": "http://www.learningregistry.org/tos/cc0/v0-5/" }, "_rev": "1-d0879e7751add53f72d1672dec4a70da", "resource_data_type": "paradata", "payload_placement": "none", "node_timestamp": "2013-06-25T10:32:28.373753Z", "doc_version": "0.49.0", "create_timestamp": "2013-06-25T10:32:28.373753Z", "active": True, "publishing_node": "bababe6a3288497fb7a46d454154f5db", "_id": "5569a004388e4621ba8b414969455f8b", "doc_ID": "5569a004388e4621ba8b414969455f8b", "identity": { "submitter": "OER Commons", "submitter_type": "agent" } } info = s.get_verification_info(doc) assert info != None, "Should have found a key to fetch."
def handle(self, replacement_rd3): # assign doc_id if need. ResourceDataModelValidator.assign_id(replacement_rd3) # validate the rd3 to be published. ResourceDataModelValidator.validate_model(replacement_rd3) # check to see if it's a replacement if replacement_rd3 is not None and _REPLACES in replacement_rd3: replacement_rd3_info = get_verification_info(replacement_rd3) if replacement_rd3_info is not None: graveyard = [] existing_gravestones = [] for orig_doc_id in replacement_rd3[_REPLACES]: try: orig_doc = self.db[orig_doc_id] orig_doc_info = get_verification_info(dict(orig_doc)) except couchdb.http.ResourceNotFound as rne: orig_doc = None orig_doc_info = None if orig_doc is not None and orig_doc[ "doc_type"] == "tombstone": permitted = True existing_gravestones.append(orig_doc) else: # verify that tombstones permitted = self._check_if_permitted( replacement_rd3, replacement_rd3_info, orig_doc, orig_doc_info) log.debug("handle: permitted? {0}".format(permitted)) if permitted: tombstone = self._make_tombstone( replacement_rd3, replacement_rd3_info, orig_doc_id, orig_doc) graveyard.append(tombstone) else: log.debug( "Replacement resource not permitted to be saved.") # this should save unless a permit plugin has thrown an exception to disallow saving result = ResourceDataModelValidator.save(replacement_rd3, skip_validation=True) if self._has_graveyard_permit(replacement_rd3, replacement_rd3_info, graveyard, existing_gravestones): for tombstone in graveyard: try: self.db[tombstone["_id"]] = tombstone except: # if this is already a tombstone, then it's okay - first wins TombstoneValidator.validate_model( self.db[tombstone["_id"]]) # else: # # import pdb; pdb.set_trace() # raise SpecValidationException("Node policy does not permit this resource published.") return result # we get here because it's not a replacement. return ResourceDataModelValidator.save(replacement_rd3, skip_validation=True)