summaryrefslogtreecommitdiffstats
path: root/ipa-python/ipaclient.py
diff options
context:
space:
mode:
authorrcritten@redhat.com <rcritten@redhat.com>2007-08-24 15:42:56 -0400
committerrcritten@redhat.com <rcritten@redhat.com>2007-08-24 15:42:56 -0400
commit861cda3cb5256a177845029ddf1900f51271b56c (patch)
tree7cf9e2004705e129511d8c25ac69232af8901317 /ipa-python/ipaclient.py
parent240a99b6f35fe7a7de37c83e69471b84298d0f56 (diff)
downloadfreeipa-861cda3cb5256a177845029ddf1900f51271b56c.tar.gz
freeipa-861cda3cb5256a177845029ddf1900f51271b56c.tar.xz
freeipa-861cda3cb5256a177845029ddf1900f51271b56c.zip
Initial support for Groups
Create separate object for Users and Groups (using same base class) Check for uniqueness before adding new users and groups Remove user_container from everything but add operations Abstract out a number of functions that are common across users and groups Make sure all strings passed in to be in a filter are checked Add new error message: No modifications specified
Diffstat (limited to 'ipa-python/ipaclient.py')
-rw-r--r--ipa-python/ipaclient.py102
1 files changed, 96 insertions, 6 deletions
diff --git a/ipa-python/ipaclient.py b/ipa-python/ipaclient.py
index dc8e1dc9b..28573acad 100644
--- a/ipa-python/ipaclient.py
+++ b/ipa-python/ipaclient.py
@@ -26,6 +26,7 @@ sys.path.append("/usr/share/ipa")
from ipaserver import funcs
import ipa.rpcclient as rpcclient
import user
+import group
import ipa
import config
@@ -54,20 +55,23 @@ class IPAClient:
if self.local:
self.transport.set_principal(princ)
+# User support
def get_user_by_uid(self,uid,sattrs=None):
"""Get a specific user by uid. If sattrs is set then only those
- attributes will be returned."""
+ attributes will be returned, otherwise all available attributes
+ are returned."""
result = self.transport.get_user_by_uid(uid,sattrs)
return user.User(result)
def get_user_by_dn(self,dn,sattrs=None):
- """Get a specific user by uid. If sattrs is set then only those
- attributes will be returned."""
+ """Get a specific user by dn. If sattrs is set then only those
+ attributes will be returned, otherwise all available attributes
+ are returned."""
result = self.transport.get_user_by_dn(dn,sattrs)
return user.User(result)
def add_user(self,user,user_container=None):
- """Add a user. user is a ipa.user object"""
+ """Add a user. user is a ipa.user.User object"""
realm = config.config.get_realm()
@@ -97,10 +101,10 @@ class IPAClient:
result = self.transport.get_add_schema()
return result
- def find_users(self, criteria, sattrs=None, user_container=None):
+ def find_users(self, criteria, sattrs=None):
"""Find users whose uid matches the criteria. Wildcards are
acceptable. Returns a list of User objects."""
- result = self.transport.find_users(criteria, sattrs, user_container)
+ result = self.transport.find_users(criteria, sattrs)
users = []
for (attrs) in result:
@@ -124,3 +128,89 @@ class IPAClient:
result = self.transport.mark_user_deleted(uid)
return result
+
+# Groups support
+
+ def get_group_by_cn(self,cn,sattrs=None):
+ """Get a specific group by cn. If sattrs is set then only those
+ attributes will be returned, otherwise all available attributes
+ are returned."""
+ result = self.transport.get_group_by_cn(cn,sattrs)
+ return group.Group(result)
+
+ def get_group_by_dn(self,dn,sattrs=None):
+ """Get a specific group by cn. If sattrs is set then only those
+ attributes will be returned, otherwise all available attributes
+ are returned."""
+ result = self.transport.get_group_by_dn(dn,sattrs)
+ return group.Group(result)
+
+ def add_group(self,group,group_container=None):
+ """Add a group. group is a ipa.group.Group object"""
+
+ realm = config.config.get_realm()
+
+ group_dict = group.toDict()
+
+ # dn is set on the server-side
+ del group_dict['dn']
+
+ # convert to a regular dict before sending
+ result = self.transport.add_group(group_dict, group_container)
+ return result
+
+ def find_groups(self, criteria, sattrs=None):
+ """Find groups whose cn matches the criteria. Wildcards are
+ acceptable. Returns a list of Group objects."""
+ result = self.transport.find_groups(criteria, sattrs)
+
+ groups = []
+ for (attrs) in result:
+ if attrs is not None:
+ groups.append(group.Group(attrs))
+
+ return groups
+
+ def add_user_to_group(self, user, group):
+ """Add a user to an existing group.
+ user is a uid of the user to add
+ group is the cn of the group to be added to
+ """
+
+ return self.transport.add_user_to_group(user, group)
+
+ def add_users_to_group(self, users, group):
+ """Add several users to an existing group.
+ user is a list of uids of the users to add
+ group is the cn of the group to be added to
+
+ Returns a list of the users that were not added.
+ """
+
+ return self.transport.add_users_to_group(users, group)
+
+ def remove_user_from_group(self, user, group):
+ """Remove a user from an existing group.
+ user is a uid of the user to remove
+ group is the cn of the group to be removed from
+ """
+
+ return self.transport.remove_user_from_group(user, group)
+
+ def remove_users_from_group(self, users, group):
+ """Remove several users from an existing group.
+ user is a list of uids of the users to remove
+ group is the cn of the group to be removed from
+
+ Returns a list of the users that were not removed.
+ """
+
+ return self.transport.remove_users_from_group(users, group)
+
+ def update_group(self,group):
+ """Update a group entry."""
+
+ realm = config.config.get_realm()
+
+ result = self.transport.update_group(group.origDataDict(), group.toDict())
+ return result