[Freeipa-devel] [PATCH] update_entry

Kevin McCarthy kmccarth at redhat.com
Mon Oct 15 16:06:21 UTC 2007


Kevin McCarthy wrote:
> Rob Crittenden wrote:
> > Kevin McCarthy wrote:
> >> This patch unifies the update_group and update_user methods into
> >> update_entry.
> >> The modivation for this was from the delegation management code, where I
> >> need to update the cn=accounts entry.  Although calling update_group()
> >> worked, it looked strange.
> >> That said, it may be just as offensive to have an API with add_user,
> >> delete_user, but update_entry.  I'm open to suggestions.
> >>
> > I don't understand how update_group looked strange.
> 
> Well, basically because it wasn't a group that I was updating, it was an
> ACI container.  So that api calls looked like
>   aci = get_aci_entry()
>   ...
>   update_group(aci)
> 
> > We can always have an update_user function that is an alias to 
> > update_entry.
> 
> Sounds like a reasonable solution to me.  Let me rework the patch,
> preserving update_user and update_group alias for update_entry.

Attached is the new version of the patch, preserving the update_user and
update_group calls.

-Kevin
-------------- next part --------------
# HG changeset patch
# User Kevin McCarthy <kmccarth at redhat.com>
# Date 1192464253 25200
# Node ID 9a29344f0870d0963529d97c3893f68d947675df
# Parent  bfbffaf14140dbccf15a9563d69e854909f80647
Creates an update_entry api call, aliases update_user and update_group to it.

diff -r bfbffaf14140 -r 9a29344f0870 ipa-python/ipaclient.py
--- a/ipa-python/ipaclient.py	Mon Oct 15 08:53:24 2007 -0700
+++ b/ipa-python/ipaclient.py	Mon Oct 15 09:04:13 2007 -0700
@@ -78,6 +78,12 @@ class IPAClient:
         result = self.transport.get_entry_by_cn(cn,sattrs)
         return entity.Entity(result)
 
+    def update_entry(self,entry):
+        """Update a entry."""
+
+        result = self.transport.update_entry(entry.origDataDict(), entry.toDict())
+        return result
+
 # User support
     def get_user_by_uid(self,uid,sattrs=None):
         """Get a specific user by uid. If sattrs is set then only those
diff -r bfbffaf14140 -r 9a29344f0870 ipa-python/rpcclient.py
--- a/ipa-python/rpcclient.py	Mon Oct 15 08:53:24 2007 -0700
+++ b/ipa-python/rpcclient.py	Mon Oct 15 09:04:13 2007 -0700
@@ -118,6 +118,20 @@ class RPCClient:
 
         return ipautil.unwrap_binary_data(result)
 
+    def update_entry(self,oldentry,newentry):
+        """Update an existing entry. oldentry and newentry are dicts of attributes"""
+        server = self.setup_server()
+
+        try:
+            result = server.update_entry(ipautil.wrap_binary_data(oldentry),
+                    ipautil.wrap_binary_data(newentry))
+        except xmlrpclib.Fault, fault:
+            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
+        except socket.error, (value, msg):
+            raise xmlrpclib.Fault(value, msg)
+
+        return ipautil.unwrap_binary_data(result)
+
 
 # User support
 
diff -r bfbffaf14140 -r 9a29344f0870 ipa-server/ipa-gui/ipagui/subcontrollers/delegation.py
--- a/ipa-server/ipa-gui/ipagui/subcontrollers/delegation.py	Mon Oct 15 08:53:24 2007 -0700
+++ b/ipa-server/ipa-gui/ipagui/subcontrollers/delegation.py	Mon Oct 15 09:04:13 2007 -0700
@@ -62,8 +62,7 @@ class DelegationController(IPAController
             aci_entry = client.get_aci_entry(['dn'])
             aci_entry.setValue('aci', new_aci.export_to_string())
 
-            # TODO - add a client.update_entry() call instead
-            client.update_group(aci_entry)
+            client.update_entry(aci_entry)
         except ipaerror.IPAError, e:
             turbogears.flash("Delgate add failed: " + str(e))
             return dict(form=delegate_new_form, delegate=kw,
diff -r bfbffaf14140 -r 9a29344f0870 ipa-server/xmlrpc-server/funcs.py
--- a/ipa-server/xmlrpc-server/funcs.py	Mon Oct 15 08:53:24 2007 -0700
+++ b/ipa-server/xmlrpc-server/funcs.py	Mon Oct 15 09:04:13 2007 -0700
@@ -343,6 +343,10 @@ class IPAServer:
         filter = "(cn=" + cn + ")"
         return self.__get_sub_entry(self.basedn, filter, sattrs, opts)
 
+    def update_entry (self, oldentry, newentry, opts=None):
+        """Update an entry in LDAP"""
+        return self.__update_entry(oldentry, newentry, opts)
+
 # User support
 
     def __is_user_unique(self, uid, opts):
@@ -586,9 +590,7 @@ class IPAServer:
 
         return new_dict
 
-    def update_user (self, olduser, newuser, opts=None):
-        """Update a user in LDAP"""
-        return self.__update_entry(olduser, newuser, opts)
+    update_user = update_entry
 
     def mark_user_deleted (self, uid, opts=None):
         """Mark a user as inactive in LDAP. We aren't actually deleting
@@ -987,9 +989,7 @@ class IPAServer:
 
         return failed
 
-    def update_group (self, oldgroup, newgroup, opts=None):
-        """Update a group in LDAP"""
-        return self.__update_entry(oldgroup, newgroup, opts)
+    update_group = update_entry
 
     def delete_group (self, group_dn, opts=None):
         """Delete a group
diff -r bfbffaf14140 -r 9a29344f0870 ipa-server/xmlrpc-server/ipaxmlrpc.py
--- a/ipa-server/xmlrpc-server/ipaxmlrpc.py	Mon Oct 15 08:53:24 2007 -0700
+++ b/ipa-server/xmlrpc-server/ipaxmlrpc.py	Mon Oct 15 09:04:13 2007 -0700
@@ -320,6 +320,7 @@ def handler(req, profiling=False):
             h.register_function(f.get_aci_entry)
             h.register_function(f.get_entry_by_dn)
             h.register_function(f.get_entry_by_cn)
+            h.register_function(f.update_entry)
             h.register_function(f.get_user_by_uid)
             h.register_function(f.get_user_by_principal)
             h.register_function(f.get_users_by_manager)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4054 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20071015/29e06258/attachment.bin>


More information about the Freeipa-devel mailing list