Hi,

the attached patch fixes part of <https://fedorahosted.org/freeipa/ticket/5150>.


Christian is working on a fix for the other part of the ticket.

Honza

--
Jan Cholasta
From a6095d43ca0df96b349c0fb9f3d69db12569a62c Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jchol...@redhat.com>
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
---
 ipalib/plugins/vault.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/ipalib/plugins/vault.py b/ipalib/plugins/vault.py
index 4d430ee..c379118 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

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to