-
- def get_printable_subject(self):
- x = self.cert.get_subject()
- return "[ OU: %s, CN: %s, SubjectAltName: %s ]" % (getattr(x, "OU"), getattr(x, "CN"), self.get_data())
+ # let's try to make this a little more usable as is makes logs hairy
+ # FIXME: Consider adding 'urn:publicid' and 'uuid' back for GENI?
+ pretty_fields = ['email']
+
+ def filter_chunk(self, chunk):
+ for field in self.pretty_fields:
+ if field in chunk:
+ return " " + chunk
+
+ def pretty_cert(self):
+ message = "[Cert."
+ x = self.x509.get_subject()
+ ou = getattr(x, "OU")
+ if ou:
+ message += " OU: {}".format(ou)
+ cn = getattr(x, "CN")
+ if cn:
+ message += " CN: {}".format(cn)
+ data = self.get_data(field='subjectAltName')
+ if data:
+ message += " SubjectAltName:"
+ counter = 0
+ filtered = [self.filter_chunk(chunk) for chunk in data.split()]
+ message += " ".join([f for f in filtered if f])
+ omitted = len([f for f in filtered if not f])
+ if omitted:
+ message += "..+{} omitted".format(omitted)
+ message += "]"
+ return message
+
+ def pretty_chain(self):
+ message = "{}".format(self.x509.get_subject())
+ parent = self.parent
+ while parent:
+ message += "->{}".format(parent.x509.get_subject())
+ parent = parent.parent
+ return message
+
+ def pretty_name(self):
+ return self.get_filename() or self.pretty_chain()