aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2013-10-28 18:53:19 +0000
committerRob Austein <sra@hactrn.net>2013-10-28 18:53:19 +0000
commitfb9b599190311c1003bd0a3dfe210d9c35a7bb3a (patch)
treedb3517cdfa4c0804d36d91a8551f6fae645b1cbc
parent4b7efc9a9af6f4e32d376412a7917f019d5c18aa (diff)
Checkpoint.
svn path=/trunk/; revision=5571
-rwxr-xr-xscripts/rcynic-lta72
1 files changed, 37 insertions, 35 deletions
diff --git a/scripts/rcynic-lta b/scripts/rcynic-lta
index 7dc0f4cf..5f1adace 100755
--- a/scripts/rcynic-lta
+++ b/scripts/rcynic-lta
@@ -150,7 +150,7 @@ class main(object):
self.rcynic_input = y["rcynic-input"]
self.rcynic_output = y["rcynic-output"]
self.keyfile = y["keyfile"]
- self.constraints = [Constraint(c) for c in y["constraints"]]
+ self.constraints = [Constraint(yc) for yc in y["constraints"]]
def parse_tals(self):
@@ -306,35 +306,33 @@ class Serial(object):
return self.value
+class ConstrainedObject(object):
-class ConstrainedROA(object):
+ def add(self):
+ raise NotImplementedError
+
+ def drop(self, constraint):
+ raise NotImplementedError
+
+class ConstrainedROA(ConstrainedObject):
def __init__(self, constraint, y):
self.constraint = constraint
- self.asn = long(y["asn"])
- self.maxlen = long(y["maxlen"]) if "maxlen" in y else None
+ self.asn = long(y["asn"]) if y is not None else None
+ self.maxlen = long(y["maxlen"]) if y is not None and "maxlen" in y else None
- def add(self):
- raise NotImplementedError
-
-class ConstrainedGBR(object):
+class ConstrainedGBR(ConstrainedObject):
def __init__(self, constraint, y):
self.constraint = constraint
self.vcard = y
- def add(self):
- raise NotImplementedError
-
-class ConstrainedRTR(object):
+class ConstrainedRTR(ConstrainedObject):
def __init__(self, constraint, y):
self.constraint = constraint
- self.key = y["key"]
- self.subject = y["subject"]
-
- def add(self):
- raise NotImplementedError
+ self.key = y["key"] if y is not None else None
+ self.subject = y["subject"] if y is not None else None
class Constraint(object):
@@ -342,30 +340,34 @@ class Constraint(object):
gbr = ConstrainedGBR,
rtr = ConstrainedRTR)
- drop_keywords = ("roas", "gbrs", "rtrs")
-
def __init__(self, y):
self.y = y # Mostly for debugging. I think.
self.prefixes = rpki.resource_set.resource_bag.from_str(str(y.get("prefix", "")))
self.asns = rpki.resource_set.resource_bag.from_str(str(y.get("asn", "")))
- drop = y.get("drop", [])
- if isinstance(drop, str):
- drop = [drop]
- if "all" in drop:
- drop = self.drop_keywords
- elif not all(d in self.drop_keywords for d in drop):
- raise ValueError("Unexpected drop keyword %r" % drop)
- for d in self.drop_keywords:
- setattr(self, "drop_" + d, d in drop)
- self.adds = []
- for a in y.get("add", ()):
- if not isinstance(a, dict) or len(a) != 1:
- raise ValueError("Expected single-entry mapping, got " + repr(a))
- k, v = a.items()[0]
- self.adds.append(self.dispatch[k](self, v))
+ self.init_drops(y.get("drop", ()))
+ self.init_adds( y.get("add", ()))
+
+ def init_drops(self, drops):
+ self.drops = []
+ if drops == "all":
+ self.drops.extend(d(self, None) for d in self.dispatch.itervalues())
+ else:
+ for d in (drops if isinstance(drops, (list, tuple)) else (drops,)):
+ if isinstance(d, str):
+ self.drops.append(self.dispatch[d[:-1]](self, None))
+ elif isinstance(d, dict) and len(d) == 1:
+ self.drops.append(self.dispatch[d.keys()[0]](self, d.values()[0]))
+ else:
+ raise ValueError("Unexpected drop clause " + repr(drops))
+
+ def init_adds(self, adds):
+ if not all(isinstance(a, dict) and len(a) == 1 for a in adds):
+ raise ValueError("Expected list of single-entry mappings, got " + repr(adds))
+ self.adds = tuple(self.dispatch[a.keys()[0]](self, a.values()[0]) for a in adds)
def drop(self):
- raise NotImplementedError
+ for d in self.drops:
+ d.drop()
def add(self):
for a in self.adds: