[CalendarServer-changes] [12888] CalendarServer/branches/users/sagen/move2who-2/txdav

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 14:28:35 PDT 2014


Revision: 12888
          http://trac.calendarserver.org//changeset/12888
Author:   sagen at apple.com
Date:     2014-03-12 14:28:35 -0700 (Wed, 12 Mar 2014)
Log Message:
-----------
Get config for OD service in a backwards compatible way

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who-2/txdav/dps/server.py
    CalendarServer/branches/users/sagen/move2who-2/txdav/who/augment.py
    CalendarServer/branches/users/sagen/move2who-2/txdav/who/directory.py

Modified: CalendarServer/branches/users/sagen/move2who-2/txdav/dps/server.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-2/txdav/dps/server.py	2014-03-12 21:22:57 UTC (rev 12887)
+++ CalendarServer/branches/users/sagen/move2who-2/txdav/dps/server.py	2014-03-12 21:28:35 UTC (rev 12888)
@@ -22,7 +22,7 @@
 from twext.python.log import Logger
 from twext.who.aggregate import DirectoryService as AggregateDirectoryService
 from twext.who.expression import MatchType, MatchFlags, Operand
-from twext.who.idirectory import RecordType
+from twext.who.idirectory import RecordType, DirectoryConfigurationError
 from twext.who.ldap import DirectoryService as LDAPDirectoryService
 from twisted.application import service
 from twisted.application.strports import service as strPortsService
@@ -454,17 +454,19 @@
     txdav.dps.client.DirectoryService
     """
 
-    # FIXME: this needs to talk to its own separate database.  In fact,
+    # MOVE2WHO FIXME: this needs to talk to its own separate database.  In fact,
     # don't pass store=None if you already have called storeFromConfig()
     # within this process.  Pass the existing store in here.
     pool, txnFactory = getDBPool(config)
     if store is None:
         store = storeFromConfig(config, txnFactory, None)
 
-    # directoryType = config.DirectoryProxy.DirectoryType
-    directoryType = config.DirectoryService.type
+    directoryType = config.DirectoryService.type.lower()
 
-    if "XML" in directoryType:
+    # MOVE2WHO FIXME:
+    # Set the appropriate record types on each service
+
+    if "xml" in directoryType:
         xmlFile = config.DirectoryService.params.xmlFile
         xmlFile = fullServerPath(config.DataRoot, xmlFile)
         # path = kwds.pop("path", "")
@@ -472,41 +474,32 @@
             log.error("Path not found for XML directory: {p}", p=xmlFile)
         fp = FilePath(xmlFile)
         primaryDirectory = XMLDirectoryService(fp)
+        log.debug(
+            "Using XML for {types}",
+            types=(", ".join([rt.name for rt in primaryDirectory.recordTypes()]))
+        )
 
+    elif "opendirectory" in directoryType:
+        from twext.who.opendirectory import DirectoryService as ODDirectoryService
+        primaryDirectory = ODDirectoryService()
 
-    # FIXME: implement the other service types
+    elif "ldap" in directoryType:
+        params = config.DirectoryService.params
+        if params.credentials.dn and params.credentials.password:
+            creds = UsernamePassword(params.credentials.dn,
+                                     params.credentials.password)
+        else:
+            creds = None
+        primaryDirectory = LDAPDirectoryService(
+            params.uri,
+            params.rdnSchema.base,
+            creds=creds
+        )
 
-    # args = config.DirectoryProxy.Arguments
-    # kwds = config.DirectoryProxy.Keywords
+    else:
+        log.error("Invalid DirectoryType: {dt}", dt=directoryType)
+        raise DirectoryConfigurationError
 
-
-    # if directoryType == "OD":
-    #     from twext.who.opendirectory import DirectoryService as ODDirectoryService
-    #     primaryDirectory = ODDirectoryService(*args, **kwds)
-
-    # elif directoryType == "LDAP":
-    #     authDN = kwds.pop("authDN", "")
-    #     password = kwds.pop("password", "")
-    #     if authDN and password:
-    #         creds = UsernamePassword(authDN, password)
-    #     else:
-    #         creds = None
-    #     kwds["credentials"] = creds
-    #     debug = kwds.pop("debug", "")
-    #     primaryDirectory = LDAPDirectoryService(
-    #         *args, _debug=debug, **kwds
-    #     )
-
-    # elif directoryType == "XML":
-    #     path = kwds.pop("path", "")
-    #     if not path or not os.path.exists(path):
-    #         log.error("Path not found for XML directory: {p}", p=path)
-    #     fp = FilePath(path)
-    #     primaryDirectory = XMLDirectoryService(fp, *args, **kwds)
-
-    # else:
-    #     log.error("Invalid DirectoryType: {dt}", dt=directoryType)
-
     #
     # Setup the Augment Service
     #

Modified: CalendarServer/branches/users/sagen/move2who-2/txdav/who/augment.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-2/txdav/who/augment.py	2014-03-12 21:22:57 UTC (rev 12887)
+++ CalendarServer/branches/users/sagen/move2who-2/txdav/who/augment.py	2014-03-12 21:28:35 UTC (rev 12888)
@@ -154,6 +154,11 @@
 
     @inlineCallbacks
     def recordWithShortName(self, recordType, shortName):
+        # log.debug(
+        #     "Augment - recordWithShortName {rt}, {n}",
+        #     rt=recordType.name,
+        #     n=shortName
+        # )
         # MOVE2WHO, REMOVE THIS:
         if not isinstance(shortName, unicode):
             log.warn("Need to change shortName to unicode")
@@ -161,6 +166,13 @@
 
         record = yield self._directory.recordWithShortName(recordType, shortName)
         record = yield self.augment(record)
+        # log.debug(
+        #     "Augment - recordWithShortName {rt}, {n} returned {r}, {u}",
+        #     rt=recordType.name,
+        #     n=shortName,
+        #     r=record.recordType.name,
+        #     u=record.uid
+        # )
         returnValue(record)
 
 

Modified: CalendarServer/branches/users/sagen/move2who-2/txdav/who/directory.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-2/txdav/who/directory.py	2014-03-12 21:22:57 UTC (rev 12887)
+++ CalendarServer/branches/users/sagen/move2who-2/txdav/who/directory.py	2014-03-12 21:28:35 UTC (rev 12888)
@@ -20,15 +20,16 @@
 
 
 import uuid
-from twext.python.log import Logger
 
-from twisted.internet.defer import inlineCallbacks, returnValue
+from twext.python.log import Logger
 from twext.who.expression import (
     MatchType, Operand, MatchExpression, CompoundExpression, MatchFlags
 )
 from twext.who.idirectory import RecordType as BaseRecordType
-from txdav.who.idirectory import RecordType as DAVRecordType
 from twisted.cred.credentials import UsernamePassword
+from twisted.internet.defer import inlineCallbacks, returnValue
+from txdav.caldav.datastore.scheduling.cuaddress import normalizeCUAddr
+from txdav.who.idirectory import RecordType as DAVRecordType
 from txweb2.auth.digest import DigestedCredentials
 
 
@@ -58,8 +59,6 @@
 
     @inlineCallbacks
     def recordWithCalendarUserAddress(self, address):
-        # FIXME: Circular
-        from txdav.caldav.datastore.scheduling.cuaddress import normalizeCUAddr
         address = normalizeCUAddr(address)
         record = None
         if address.startswith("urn:uuid:"):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/73d3f119/attachment-0001.html>


More information about the calendarserver-changes mailing list