diff options
author | Martin Basti <mbasti@redhat.com> | 2016-03-14 17:42:56 +0100 |
---|---|---|
committer | Martin Basti <mbasti@redhat.com> | 2016-04-26 13:37:23 +0200 |
commit | 14ee02dcbd6cbb6c221ac7526e471a9fc58fcc82 (patch) | |
tree | 6197b3a6506c63ee3fe163bb78ca17fe41aede3b /ipalib/util.py | |
parent | fe2ce02a6f7664e377c367e16e9c2e1ad960c9d7 (diff) | |
download | freeipa-14ee02dcbd6cbb6c221ac7526e471a9fc58fcc82.tar.gz freeipa-14ee02dcbd6cbb6c221ac7526e471a9fc58fcc82.tar.xz freeipa-14ee02dcbd6cbb6c221ac7526e471a9fc58fcc82.zip |
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 <slaznick@redhat.com>
Diffstat (limited to 'ipalib/util.py')
-rw-r--r-- | ipalib/util.py | 40 |
1 files changed, 34 insertions, 6 deletions
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. |