From 14ee02dcbd6cbb6c221ac7526e471a9fc58fcc82 Mon Sep 17 00:00:00 2001 From: Martin Basti Date: Mon, 14 Mar 2016 17:42:56 +0100 Subject: Do not do extra search for ipasshpubkey to generate fingerprints Host, user and idview commands do unnnecessary extra search for ipasshpubkey attribute to generate fingerprints. Note: Host and user plugins shows ipasshpubkey only when the attribute is changed, idviews show ipasshpubkey always. This behavior has been kept by this commit. common_pre/post_callbacks were fixed in [base|stage]user modules. common_callbacks requires the same arguments as pre/post_callbacks now (except baseuser_find.post_common_callback) Note2: in *-add commands there is no need for managing ipasshpubkey as this attribute should be shown always there. https://fedorahosted.org/freeipa/ticket/3376 Reviewed-By: Stanislav Laznicka --- ipalib/util.py | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'ipalib/util.py') diff --git a/ipalib/util.py b/ipalib/util.py index 262acf926..709bfbb8e 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -290,12 +290,9 @@ def validate_sshpubkey_no_options(ugettext, value): if pubkey.has_options(): return _('options are not allowed') -def convert_sshpubkey_post(ldap, dn, entry_attrs): - if 'ipasshpubkey' in entry_attrs: - pubkeys = entry_attrs['ipasshpubkey'] - else: - old_entry_attrs = ldap.get_entry(dn, ['ipasshpubkey']) - pubkeys = old_entry_attrs.get('ipasshpubkey') + +def convert_sshpubkey_post(entry_attrs): + pubkeys = entry_attrs.get('ipasshpubkey') if not pubkeys: return @@ -321,6 +318,37 @@ def convert_sshpubkey_post(ldap, dn, entry_attrs): if fingerprints: entry_attrs['sshpubkeyfp'] = fingerprints + +def add_sshpubkey_to_attrs_pre(context, attrs_list): + """ + Attribute ipasshpubkey should be added to attrs_list to be able compute + ssh fingerprint. This attribute must be removed later if was added here + (see remove_sshpubkey_from_output_post). + """ + if not ('ipasshpubkey' in attrs_list or '*' in attrs_list): + setattr(context, 'ipasshpubkey_added', True) + attrs_list.append('ipasshpubkey') + + +def remove_sshpubkey_from_output_post(context, entry_attrs): + """ + Remove ipasshpubkey from output if it was added in pre_callbacks + """ + if getattr(context, 'ipasshpubkey_added', False): + entry_attrs.pop('ipasshpubkey', None) + delattr(context, 'ipasshpubkey_added') + + +def remove_sshpubkey_from_output_list_post(context, entries): + """ + Remove ipasshpubkey from output if it was added in pre_callbacks + """ + if getattr(context, 'ipasshpubkey_added', False): + for entry_attrs in entries: + entry_attrs.pop('ipasshpubkey', None) + delattr(context, 'ipasshpubkey_added') + + class cachedproperty(object): """ A property-like attribute that caches the return value of a method call. -- cgit