summaryrefslogtreecommitdiffstats
path: root/ipa-python
diff options
context:
space:
mode:
authorrcritten@redhat.com <rcritten@redhat.com>2007-08-23 09:44:00 -0400
committerrcritten@redhat.com <rcritten@redhat.com>2007-08-23 09:44:00 -0400
commit8879ee173ec6814da701464c562471a3c8c5d846 (patch)
treecb19a6a5ed58e588313b140330f5b2022b153b18 /ipa-python
parent23508d33b5d9de287411aeead9b3937cc8661093 (diff)
downloadfreeipa-8879ee173ec6814da701464c562471a3c8c5d846.tar.gz
freeipa-8879ee173ec6814da701464c562471a3c8c5d846.tar.xz
freeipa-8879ee173ec6814da701464c562471a3c8c5d846.zip
Handle optional arguments by using the value __NONE__ over XML-RPC.
rpcclient.py must call XML-RPC functions with all arguments. Removed encode_args and decode_args. They were the source of most of the argument pain. Now opts is alwyas appended to the end of the arguments so MUST be the last argument in any server-side function (can be None) Allow the User object to handle unicode data Small fixes to command-line tools to be friendlier Broke out get_user() into get_user_by_dn() and get_user_by_uid() Need to request more than just 'nsAccountLock' attribute when trying to see if a user is already marked deleted. If it is blank the record coming back is empty. Add 'uid' to the list to guarantee something coming back (dn is handled specially) Added user_container attribute to get_user_* and add_user so the caller can specify where in the tree the user will be searched for/added. Added global default value for user_container
Diffstat (limited to 'ipa-python')
-rw-r--r--ipa-python/ipaclient.py18
-rw-r--r--ipa-python/rpcclient.py43
-rw-r--r--ipa-python/user.py2
3 files changed, 44 insertions, 19 deletions
diff --git a/ipa-python/ipaclient.py b/ipa-python/ipaclient.py
index 44c61c6ae..d7450f5ca 100644
--- a/ipa-python/ipaclient.py
+++ b/ipa-python/ipaclient.py
@@ -54,13 +54,19 @@ class IPAClient:
if self.local:
self.transport.set_principal(princ)
- def get_user(self,uid,sattrs=None):
+ 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."""
- result = self.transport.get_user(uid,sattrs)
+ result = self.transport.get_user_by_uid(uid,sattrs)
return user.User(result)
- def add_user(self,user):
+ 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."""
+ 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"""
realm = config.config.get_realm()
@@ -87,7 +93,7 @@ class IPAClient:
del user_dict['dn']
# convert to a regular dict before sending
- result = self.transport.add_user(user_dict)
+ result = self.transport.add_user(user_dict, user_container)
return result
def get_all_users(self):
@@ -107,10 +113,10 @@ class IPAClient:
result = self.transport.get_add_schema()
return result
- def find_users(self, criteria, sattrs=None):
+ def find_users(self, criteria, sattrs=None, user_container=None):
"""Find users whose uid matches the criteria. Wildcards are
acceptable. Returns a list of User objects."""
- result = self.transport.find_users(criteria, sattrs)
+ result = self.transport.find_users(criteria, sattrs, user_container)
users = []
for (attrs) in result:
diff --git a/ipa-python/rpcclient.py b/ipa-python/rpcclient.py
index d5a2d4262..cd94eb99c 100644
--- a/ipa-python/rpcclient.py
+++ b/ipa-python/rpcclient.py
@@ -67,15 +67,29 @@ class RPCClient:
return user
- def get_user(self,username,sattrs=None):
+ def get_user_by_uid(self,uid,sattrs=None):
"""Get a specific user. If sattrs is not None then only those
attributes will be returned. The result is a dict."""
server = self.setup_server()
+ if sattrs is None:
+ sattrs = "__NONE__"
try:
- if sattrs is not None:
- result = server.get_user(username,sattrs)
- else:
- result = server.get_user(username)
+ result = server.get_user_by_uid(uid, sattrs)
+ except xmlrpclib.Fault, fault:
+ raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
+ except socket.error, (value, msg):
+ raise xmlrpclib.Fault(value, msg)
+
+ return result
+
+ def get_user_by_dn(self,dn,sattrs=None):
+ """Get a specific user. If sattrs is not None then only those
+ attributes will be returned. The result is a dict."""
+ server = self.setup_server()
+ if sattrs is None:
+ sattrs = "__NONE__"
+ try:
+ result = server.get_user_by_dn(dn, sattrs)
except xmlrpclib.Fault, fault:
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
except socket.error, (value, msg):
@@ -83,14 +97,17 @@ class RPCClient:
return result
- def add_user(self,user):
+ def add_user(self,user,user_container=None):
"""Add a new user. Takes as input a dict where the key is the
attribute name and the value is either a string or in the case
of a multi-valued field a list of values"""
server = self.setup_server()
+
+ if user_container is None:
+ user_container = "__NONE__"
try:
- result = server.add_user(user)
+ result = server.add_user(user, user_container)
except xmlrpclib.Fault, fault:
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
except socket.error, (value, msg):
@@ -128,16 +145,18 @@ class RPCClient:
return result
- def find_users (self, criteria, sattrs=None):
+ def find_users (self, criteria, sattrs=None, user_container=None):
"""Return a list containing a User object for each user that matches
the criteria."""
server = self.setup_server()
try:
- if sattrs is not None:
- result = server.find_users(criteria, sattrs)
- else:
- result = server.find_users(criteria)
+ # None values are not allowed in XML-RPC
+ if sattrs is None:
+ sattrs = "__NONE__"
+ if user_container is None:
+ user_container = "__NONE__"
+ result = server.find_users(criteria, sattrs, user_container)
except xmlrpclib.Fault, fault:
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
except socket.error, (value, msg):
diff --git a/ipa-python/user.py b/ipa-python/user.py
index dd0afb578..9d547e80d 100644
--- a/ipa-python/user.py
+++ b/ipa-python/user.py
@@ -33,7 +33,7 @@ class User:
if isinstance(entrydata,tuple):
self.dn = entrydata[0]
self.data = ldap.cidict.cidict(entrydata[1])
- elif isinstance(entrydata,str):
+ elif isinstance(entrydata,str) or isinstance(entrydata,unicode):
self.dn = entrydata
self.data = ldap.cidict.cidict()
elif isinstance(entrydata,dict):