From 45947b187184797e755151deee473da6d3daaa6f Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Mon, 17 Feb 2014 22:08:07 +0100 Subject: [PATCH] =?UTF-8?q?[attributs]=20sshFingerping=20:=20repr=C3=A9sen?= =?UTF-8?q?tation=20ldap=20comme=20in=20dict=20{type,=20clef,=20commentair?= =?UTF-8?q?e}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attributs.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/attributs.py b/attributs.py index 0d12bfe..c4152a7 100644 --- a/attributs.py +++ b/attributs.py @@ -1254,6 +1254,37 @@ class sshFingerprint(Attr): legend = "Clef ssh de la machine" can_modify = [parent, nounou] ldap_name = "sshFingerprint" + python_type = dict + + def parse_value(self, key): + if isinstance(key, self.python_type): + if set(key.keys()).issuperset(['type', 'key']): + details = [ key['type'], key['key'] ] + if 'comm' in key: + details.append(key['comm']) + else: + raise ValueError("sshFingerprint should have a type dans a key field") + else: + details = key.split() + if len(details)<2: + raise ValueError("Une clef ssh devrait être de la forme : 'format clef commentaire' comme 'ssh-dss AAAAB3NzaC… root@mon-pc' par exemple") + self.value = { 'type' : details[0], + 'key' : details[1], + 'comm' : ' '.join(details[2:]), + } + def __getitem__(self, attr): + return self.value.__getitem__(attr) + + def __setitem__(self, attr, values): + if attr in ['comm']: + ret=self.value.__setitem__(attr, values) + self.parse_value(unicode(self)) + return ret + else: + raise ValueError("sshFingerprint has no %r editable" % attr) + + def __unicode__(self): + return u'%(type)s %(key)s %(comm)s' % self.value @crans_attribute class gpgFingerprint(Attr):