diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/irbe-cli.py | 91 | ||||
-rw-r--r-- | scripts/rpki/relaxng.py | 10 |
2 files changed, 40 insertions, 61 deletions
diff --git a/scripts/irbe-cli.py b/scripts/irbe-cli.py index e446c47a..da9906ab 100755 --- a/scripts/irbe-cli.py +++ b/scripts/irbe-cli.py @@ -8,86 +8,69 @@ import glob, rpki.left_right, rpki.relaxng, getopt, sys, lxml.etree class command(object): - booleans = () - def getopt(self, argv): - opts, args = getopt.getopt(argv, "", [x + "=" for x in self.pdu.attributes] + [x for x in self.pdu.booleans]) + opts, args = getopt.getopt(argv, "", [x + "=" for x in self.attributes] + [x for x in self.booleans]) for o, a in opts: o = o[2:] - handler = getattr(self, o, None) + handler = getattr(self, "handle_" + o, None) if handler is not None: handler(a) - elif o in self.pdu.booleans: - setattr(self.pdu, o, True) + elif o in self.booleans: + setattr(self, o, True) else: - assert o in self.pdu.attributes - setattr(self.pdu, o, a) + assert o in self.attributes + setattr(self, o, a) return args def process(self, msg, argv): argv = self.getopt(argv) - msg.append(self.pdu) + msg.append(self) return argv - def action(self, arg): - self.pdu.action = arg - self.pdu.type = "query" - - def peer_ta(self, arg): - self.pdu.peer_ta = read_cert(arg) + def handle_action(self, arg): + self.action = arg + self.type = "query" -class self(command): + def handle_peer_ta(self, arg): + self.peer_ta = read_cert(arg) - def __init__(self): - self.pdu = rpki.left_right.self_elt() +class self(command, rpki.left_right.self_elt): - def extension(self, arg): + def handle_extension(self, arg): kv = arg.split(":", 1) - self.pdu.extensions[k] = v - -class bsc(command): - - def __init__(self): - self.pdu = rpki.left_right.bsc_elt() - - def signing_cert(self, arg): - self.pdu.signing_cert.append(read_cert(arg)) - -class parent(command): - - def __init__(self): - self.pdu = rpki.left_right.parent_elt() + self.extensions[k] = v -class child(command): +class bsc(command, rpki.left_right.bsc_elt): - def __init__(self): - self.pdu = rpki.left_right.child_elt() + def handle_signing_cert(self, arg): + self.signing_cert.append(read_cert(arg)) -class repository(command): +class parent(command, rpki.left_right.parent_elt): + pass - def __init__(self): - self.pdu = rpki.left_right.repository_elt() +class child(command, rpki.left_right.child_elt): + pass -class route_origin(command): +class repository(command, rpki.left_right.repository_elt): + pass - def __init__(self): - self.pdu = rpki.left_right.route_origin_elt() +class route_origin(command, rpki.left_right.route_origin_elt): - def asn(self, arg): - self.pdu.asn = long(arg) + def handle_asn(self, arg): + self.asn = long(arg) - def ipv4(self, arg): - self.pdu.ipv4 = resource_set.resource_set_ipv4(arg) + def handle_ipv4(self, arg): + self.ipv4 = resource_set.resource_set_ipv4(arg) - def ipv6(self, arg): - self.pdu.ipv6 = resource_set.resource_set_ipv6(arg) + def handle_ipv6(self, arg): + self.ipv6 = resource_set.resource_set_ipv6(arg) dispatch = dict((x.__name__, x) for x in (self, bsc, parent, child, repository, route_origin)) def usage(): print "Usage:", sys.argv[0] for k,v in dispatch.iteritems(): - print " ", k, " ".join(["--" + x + "=x" for x in v.attributes]), " ".join(["--" + x for x in v.booleans]) + print " ", k, " ".join(["--" + x + "=" for x in v.attributes]), " ".join(["--" + x for x in v.booleans]) sys.exit(1) rng = rpki.relaxng.RelaxNG("left-right-schema.rng") @@ -107,5 +90,11 @@ else: if msg: elt = msg.toXML() - rng.assertValid(elt) - print lxml.etree.tostring(elt, pretty_print=True, encoding="us-ascii", xml_declaration=True) + xml = lxml.etree.tostring(elt, pretty_print=True, encoding="us-ascii", xml_declaration=True) + try: + rng.assertValid(elt) + except lxml.etree.DocumentInvalid: + print "Generated request document doesn't pass schema check:" + print xml + sys.exit(1) + print xml diff --git a/scripts/rpki/relaxng.py b/scripts/rpki/relaxng.py index bbfc6d72..1478b66f 100644 --- a/scripts/rpki/relaxng.py +++ b/scripts/rpki/relaxng.py @@ -12,13 +12,3 @@ class RelaxNG(lxml.etree.RelaxNG): Initialize a RelaxNG validator from a file. """ lxml.etree.RelaxNG.__init__(self, lxml.etree.parse(filename)) - - def assertValid(self, doc): - """ - Provide a bit more information on validation failures. - """ - try: - lxml.etree.RelaxNG.assertValid(self, doc) - except lxml.etree.DocumentInvalid: - print self.error_log.last_error - raise |