summaryrefslogtreecommitdiffstats
path: root/ipaserver
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2013-01-22 09:58:53 +0100
committerMartin Kosek <mkosek@redhat.com>2013-03-01 16:59:43 +0100
commitc1d6937ea274256e8a4422e3415670567f07dd4e (patch)
treeccfeb88848e77d19b5c8b0ad810e0fcb6378f77e /ipaserver
parent8d92ca851c6a0d3380ddbe13c3b442adab274f93 (diff)
downloadfreeipa.git-c1d6937ea274256e8a4422e3415670567f07dd4e.tar.gz
freeipa.git-c1d6937ea274256e8a4422e3415670567f07dd4e.tar.xz
freeipa.git-c1d6937ea274256e8a4422e3415670567f07dd4e.zip
Remove the Entity class.
Move Entity functionality to LDAPEntry.
Diffstat (limited to 'ipaserver')
-rw-r--r--ipaserver/install/ldapupdate.py35
-rw-r--r--ipaserver/ipaldap.py52
2 files changed, 48 insertions, 39 deletions
diff --git a/ipaserver/install/ldapupdate.py b/ipaserver/install/ldapupdate.py
index d2a23e55..a35df371 100644
--- a/ipaserver/install/ldapupdate.py
+++ b/ipaserver/install/ldapupdate.py
@@ -33,7 +33,6 @@ import pwd
import fnmatch
import csv
import inspect
-import copy
import krbV
import ldap
@@ -49,29 +48,6 @@ from ipapython.ipa_log_manager import *
from ipaserver.install.plugins import PRE_UPDATE, POST_UPDATE
-class Entity(ipaldap.Entry):
- # TODO: Use ldap2 instead
- def __init__(self, entrydata=None):
- ipaldap.Entry.__init__(self, entrydata)
- y = {}
- for key, value in self.data.iteritems():
- y[copy.deepcopy(key)] = copy.deepcopy(value)
- self.orig_data = ipautil.CIDict(y)
-
- def attrList(self):
- """Return a list of all attributes in the entry"""
- return self.data.keys()
-
- def origDataDict(self):
- """Returns a dict of the original values of the user.
-
- Used for updates.
- """
- result = ipautil.CIDict(self.orig_data)
- result['dn'] = self.dn
- return result
-
-
class BadSyntax(installutils.ScriptError):
def __init__(self, value):
self.value = value
@@ -269,18 +245,15 @@ class LDAPUpdate:
return text
def _entry_to_entity(self, ent):
- """Tne Entry class is a bare LDAP entry. The Entity class has a lot more
- helper functions that we need, so convert to dict and then to Entity.
- """
- entry = dict(ent.data)
- entry['dn'] = ent.dn
+ entry = ent.copy()
for key,value in entry.iteritems():
if isinstance(value,list) or isinstance(value,tuple):
if len(value) == 0:
entry[key] = ''
elif len(value) == 1:
entry[key] = value[0]
- return Entity(entry)
+ entry.commit()
+ return entry
def _combine_updates(self, all_updates, update):
'Combine a new update with the list of total updates'
@@ -508,7 +481,7 @@ class LDAPUpdate:
def _create_default_entry(self, dn, default):
"""Create the default entry from the values provided.
- The return type is Entity
+ The return type is ipaldap.Entry
"""
assert isinstance(dn, DN)
entry = self.conn.make_entry(dn)
diff --git a/ipaserver/ipaldap.py b/ipaserver/ipaldap.py
index e3c74f83..9f7a0e9d 100644
--- a/ipaserver/ipaldap.py
+++ b/ipaserver/ipaldap.py
@@ -26,6 +26,7 @@ import string
import time
import shutil
from decimal import Decimal
+from copy import deepcopy
import ldap
import ldap as _ldap
@@ -586,20 +587,32 @@ class IPASimpleLDAPObject(object):
# r[0] == r.dn
# r[1] == r.data
class LDAPEntry(dict):
- __slots__ = ('_dn',)
+ __slots__ = ('_dn', '_orig')
def __init__(self, _dn=None, _obj=None, **kwargs):
+ super(LDAPEntry, self).__init__()
+
if isinstance(_dn, LDAPEntry):
assert _obj is None
_obj = _dn
- self._dn = DN(_obj._dn) #pylint: disable=E1103
+ _dn = DN(_dn._dn)
+
+ if isinstance(_obj, LDAPEntry):
+ orig = _obj._orig
else:
- assert isinstance(_dn, DN)
if _obj is None:
_obj = {}
- self._dn = _dn
+ orig = None
+
+ assert isinstance(_dn, DN)
+
+ self._dn = _dn
+ self._orig = orig
- super(LDAPEntry, self).__init__(self._init_iter(_obj, **kwargs))
+ if orig is None:
+ self.commit()
+
+ self.update(_obj, **kwargs)
# properties for Entry and Entity compatibility
@property
@@ -616,6 +629,11 @@ class LDAPEntry(dict):
# FIXME: for backwards compatibility only
return self
+ @property
+ def orig_data(self):
+ # FIXME: for backwards compatibility only
+ return self._orig
+
def _attr_name(self, name):
if not isinstance(name, basestring):
raise TypeError(
@@ -637,6 +655,10 @@ class LDAPEntry(dict):
def copy(self):
return LDAPEntry(self)
+ def commit(self):
+ self._orig = self
+ self._orig = deepcopy(self)
+
def __setitem__(self, name, value):
super(LDAPEntry, self).__setitem__(self._attr_name(name), value)
@@ -733,6 +755,19 @@ class LDAPEntry(dict):
result['dn'] = self.dn
return result
+ def attrList(self):
+ """Return a list of all attributes in the entry"""
+ return self.data.keys()
+
+ def origDataDict(self):
+ """Returns a dict of the original values of the user.
+
+ Used for updates.
+ """
+ result = ipautil.CIDict(self.orig_data)
+ result['dn'] = self.dn
+ return result
+
class Entry(LDAPEntry):
"""For compatibility with old code only
@@ -750,7 +785,7 @@ class Entry(LDAPEntry):
a search result entry or a reference or None.
If creating a new empty entry, data is the string DN."""
if entrydata:
- if isinstance(entrydata, (tuple, LDAPEntry)):
+ if isinstance(entrydata, tuple):
dn = entrydata[0]
data = ipautil.CIDict(entrydata[1])
elif isinstance(entrydata, DN):
@@ -759,9 +794,10 @@ class Entry(LDAPEntry):
elif isinstance(entrydata, basestring):
dn = DN(entrydata)
data = ipautil.CIDict()
+ elif isinstance(entrydata, LDAPEntry):
+ dn = entrydata.dn
+ data = entrydata
elif isinstance(entrydata, dict):
- if hasattr(entrydata, 'dn'):
- entrydata['dn'] = entrydata.dn
dn = entrydata['dn']
del entrydata['dn']
data = ipautil.CIDict(entrydata)