Created
April 29, 2013 20:47
-
-
Save jimklo/5484651 to your computer and use it in GitHub Desktop.
Publishing a LR Delete
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"documents": [{ | |
"doc_type": "resource_data", | |
"doc_version": "0.49.0", | |
"doc_ID": "urn:learningregistry.org:testing:uuid:C134DD8D-6580-4A68-B456-506B07D5A288", | |
"resource_data_type": "paradata", | |
"active": true, | |
"resource_locator": "http://example.com", | |
"resource_data": { | |
"testing": "this can be ignored" | |
}, | |
"identity": { | |
"submitter_type": "agent", | |
"owner": "Jim Klo", | |
"curator": "Jim Klo <jim@learningregistry.org>" | |
}, | |
"TOS": { | |
"submission_TOS": "http://creativecommons.org/publicdomain/zero/1.0/legalcode" | |
}, | |
"payload_schema": ["testing"], | |
"payload_placement": "inline" | |
}, { | |
"doc_ID": "urn:learningregistry.org:testing:uuid:C2879C2E-660C-47A5-8585-6B863D445324", | |
"doc_type": "resource_data", | |
"doc_version": "0.49.0", | |
"replaces": ["urn:learningregistry.org:testing:uuid:C134DD8D-6580-4A68-B456-506B07D5A288"], | |
"resource_data_type": "paradata", | |
"active": true, | |
"identity": { | |
"submitter_type": "agent", | |
"owner": "Jim Klo", | |
"curator": "Jim Klo <jim@learningregistry.org>" | |
}, | |
"TOS": { | |
"submission_TOS": "http://creativecommons.org/publicdomain/zero/1.0/legalcode" | |
}, | |
"payload_placement": "none" | |
}] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse, base64, uuid, json, urllib2 | |
from LRSignature.sign.Sign import Sign_0_21 | |
headers = { | |
"content-type": "application/json; charset=utf-8" | |
} | |
server = "http://sandbox.learningregistry.org" | |
def make_id(): | |
uid = "urn:www.example.com:uuid1:%s" % uuid.uuid1() | |
version = 0 | |
while True: | |
yield "{uid}-{version}".format(uid=uid, version=version) | |
version += 1 | |
def sign_and_publish(doc, key, passphrase): | |
signer = Sign_0_21(key, passphrase, gpgbin="gpg", publicKeyLocations=["http://www.example.com/publickey/"]) | |
signed = signer.sign(doc) | |
return signed | |
if "__main__" == __name__: | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-u', '--user', help="publish user", required=True) | |
parser.add_argument('-pw', '--passwd', help="publis passwd", required=True) | |
parser.add_argument('-s', '--submitter', help="submitter", default="Jim Klo <jim@sri.com>") | |
parser.add_argument('-p', '--passphrase', help="GPG Passphrase", default=None) | |
parser.add_argument('-k', '--key', help="GPG Key ID", default="A8A790EA220403B7") | |
args = parser.parse_args() | |
published_ids = [] | |
with open("./replacment-data.json") as f: | |
pwd_str = "%s:%s" % (args.user, args.passwd ) | |
auth_header = { | |
"Authorization": "Basic {0}".format(base64.b64encode(pwd_str)) | |
} | |
auth_header.update(headers) | |
docs = json.load(f) | |
id_gen = make_id() | |
for idx, doc in enumerate(docs["documents"]): | |
published_ids.append(id_gen.next()) | |
doc["doc_ID"] = published_ids[-1] | |
doc["identity"]["submitter"] = args.submitter | |
if len(published_ids) > 1: | |
doc["replaces"] = published_ids[-2:-1] | |
signed = sign_and_publish(doc, args.key, args.passphrase) | |
print signed, "\n" | |
request = urllib2.Request("%s/publish" % server, headers=auth_header) | |
resp = urllib2.urlopen(request, data=json.dumps({ "documents":[signed] })) | |
print resp.read(), "\n\n" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment