From 23dd6ad21e09a14a802c7776bf073f22011f7eb6 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Tue, 18 Aug 2015 21:44:13 +0200 Subject: [PATCH] vault: Add container information to vault command results https://fedorahosted.org/freeipa/ticket/5150 Reviewed-By: Petr Vobornik --- ipalib/plugins/vault.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/ipalib/plugins/vault.py b/ipalib/plugins/vault.py index ff021a6a2106b6bcbd690b50bf58e49249e80500..712e2d5ddfa723eb84b80a261289a7cf1c75674f 100644 --- a/ipalib/plugins/vault.py +++ b/ipalib/plugins/vault.py @@ -322,6 +322,21 @@ class vault(LDAPObject): label=_('Failed owners'), flags=['no_create', 'no_update', 'no_search'], ), + Str( + 'service?', + label=_('Vault service'), + flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'}, + ), + Flag( + 'shared?', + label=_('Shared vault'), + flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'}, + ), + Str( + 'username?', + label=_('Vault user'), + flags={'virtual_attribute', 'no_create', 'no_update', 'no_search'}, + ), ) def get_dn(self, *keys, **options): @@ -523,6 +538,17 @@ class vault(LDAPObject): raise errors.AuthenticationError( message=_('Invalid credentials')) + def get_container_attribute(self, entry, options): + if options.get('raw', False): + return + container_dn = DN(self.container_dn, self.api.env.basedn) + if entry.dn.endswith(DN(('cn', 'services'), container_dn)): + entry['service'] = entry.dn[1]['cn'] + elif entry.dn.endswith(DN(('cn', 'shared'), container_dn)): + entry['shared'] = True + elif entry.dn.endswith(DN(('cn', 'users'), container_dn)): + entry['username'] = entry.dn[1]['cn'] + @register() class vault_add(PKQuery, Local): @@ -738,6 +764,10 @@ class vault_add_internal(LDAPCreate): return dn + def post_callback(self, ldap, dn, entry, *keys, **options): + self.obj.get_container_attribute(entry, options) + return dn + @register() class vault_del(LDAPDelete): @@ -806,6 +836,11 @@ class vault_find(LDAPSearch): return (filter, base_dn, scope) + def post_callback(self, ldap, entries, truncated, *args, **options): + for entry in entries: + self.obj.get_container_attribute(entry, options) + return truncated + def exc_callback(self, args, options, exc, call_func, *call_args, **call_kwargs): if call_func.__name__ == 'find_entries': @@ -836,6 +871,10 @@ class vault_mod(LDAPUpdate): return dn + def post_callback(self, ldap, dn, entry_attrs, *keys, **options): + self.obj.get_container_attribute(entry_attrs, options) + return dn + @register() class vault_show(LDAPRetrieve): @@ -854,6 +893,10 @@ class vault_show(LDAPRetrieve): return dn + def post_callback(self, ldap, dn, entry_attrs, *keys, **options): + self.obj.get_container_attribute(entry_attrs, options) + return dn + @register() class vaultconfig(Object): @@ -1452,6 +1495,7 @@ class VaultModMember(LDAPModMember): def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options): for fail in failed.itervalues(): fail['services'] = fail.pop('service', []) + self.obj.get_container_attribute(entry_attrs, options) return completed, dn -- 2.4.3