[CalendarServer-changes] [12624] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:18:32 PDT 2014


Revision: 12624
          http://trac.calendarserver.org//changeset/12624
Author:   sagen at apple.com
Date:     2014-02-08 14:59:17 -0800 (Sat, 08 Feb 2014)
Log Message:
-----------
Allow configuration of the various DPS services via plist

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/stdconfig.py
    CalendarServer/trunk/txdav/dps/client.py
    CalendarServer/trunk/txdav/dps/server.py
    CalendarServer/trunk/txdav/dps/test/test_client.py

Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py	2014-02-08 22:54:32 UTC (rev 12623)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py	2014-02-08 22:59:17 UTC (rev 12624)
@@ -836,6 +836,8 @@
         "Enabled": False,
         "SocketPath": "directory-proxy.sock",
         "DirectoryType": "XML",  # "LDAP", "OD", "XML"
+        "Arguments": [],
+        "Keywords": {},
     },
 
     #

Modified: CalendarServer/trunk/txdav/dps/client.py
===================================================================
--- CalendarServer/trunk/txdav/dps/client.py	2014-02-08 22:54:32 UTC (rev 12623)
+++ CalendarServer/trunk/txdav/dps/client.py	2014-02-08 22:59:17 UTC (rev 12624)
@@ -207,14 +207,17 @@
 @inlineCallbacks
 def makeEvenBetterRequest():
     ds = DirectoryService(None)
-    record = (yield ds.recordWithShortName(RecordType.user, "wsanchez"))
+    record = (yield ds.recordWithShortName(RecordType.user, "sagen"))
     print("short name: {r}".format(r=record))
+    if record:
+        authenticated = (yield record.verifyPlaintextPassword("secret"))
+        print("plain auth: {a}".format(a=authenticated))
+    """
     record = (yield ds.recordWithUID("__dre__"))
     print("uid: {r}".format(r=record))
     if record:
         authenticated = (yield record.verifyPlaintextPassword("erd"))
         print("plain auth: {a}".format(a=authenticated))
-    """
     record = (yield ds.recordWithGUID("A3B1158F-0564-4F5B-81E4-A89EA5FF81B0"))
     print("guid: {r}".format(r=record))
     records = (yield ds.recordsWithRecordType(RecordType.user))

Modified: CalendarServer/trunk/txdav/dps/server.py
===================================================================
--- CalendarServer/trunk/txdav/dps/server.py	2014-02-08 22:54:32 UTC (rev 12623)
+++ CalendarServer/trunk/txdav/dps/server.py	2014-02-08 22:59:17 UTC (rev 12624)
@@ -15,6 +15,7 @@
 ##
 
 import cPickle as pickle
+import os
 import uuid
 
 from twext.python.log import Logger
@@ -36,8 +37,10 @@
     VerifyPlaintextPasswordCommand, VerifyHTTPDigestCommand,
     # UpdateRecordsCommand, RemoveRecordsCommand
 )
+from twext.who.ldap import DirectoryService as LDAPDirectoryService
 from txdav.who.xml import DirectoryService as XMLDirectoryService
 from zope.interface import implementer
+from twisted.cred.credentials import UsernamePassword
 
 log = Logger()
 
@@ -320,6 +323,14 @@
     description = "Directory Proxy Service"
     options = DirectoryProxyOptions
 
+    def _extractKeyword(self, key, kwds):
+        result = ""
+        if key in kwds:
+            result = kwds[key]
+            del kwds[key]
+        return result
+
+
     def makeService(self, options):
         """
         Return a service
@@ -332,17 +343,33 @@
             setproctitle("CalendarServer Directory Proxy Service")
 
         directoryType = config.DirectoryProxy.DirectoryType
+        args = config.DirectoryProxy.Arguments
+        kwds = config.DirectoryProxy.Keywords
+
         if directoryType == "OD":
-            directory = ODDirectoryService()
+            directory = ODDirectoryService(*args, **kwds)
+
         elif directoryType == "LDAP":
-            pass
+            authDN = self._extractKeyword("authDN", kwds)
+            password = self._extractKeyword("password", kwds)
+            if authDN and password:
+                creds = UsernamePassword(authDN, password)
+            else:
+                creds = None
+            kwds["credentials"] = creds
+            debug = self._extractKeyword("debug", kwds)
+            directory = LDAPDirectoryService(*args, _debug=debug, **kwds)
+
         elif directoryType == "XML":
-            path = "txdav/dps/test/test.xml"
-            directory = XMLDirectoryService(FilePath(path))
+            path = self._extractKeyword("path", kwds)
+            if not path or not os.path.exists(path):
+                log.error("Path not found for XML directory: {p}", p=path)
+            fp = FilePath(path)
+            directory = XMLDirectoryService(fp, *args, **kwds)
+
         else:
             log.error("Invalid DirectoryType: {dt}", dt=directoryType)
 
-
         desc = "unix:{path}:mode=660".format(
             path=config.DirectoryProxy.SocketPath
         )

Modified: CalendarServer/trunk/txdav/dps/test/test_client.py
===================================================================
--- CalendarServer/trunk/txdav/dps/test/test_client.py	2014-02-08 22:54:32 UTC (rev 12623)
+++ CalendarServer/trunk/txdav/dps/test/test_client.py	2014-02-08 22:59:17 UTC (rev 12624)
@@ -31,7 +31,7 @@
 if testMode == "xml":
     from txdav.who.xml import DirectoryService as XMLDirectoryService
 elif testMode == "od":
-    odpw = "__secret__"
+    odpw = "secret"
     from twext.who.opendirectory import DirectoryService as OpenDirectoryService
 
 
@@ -118,13 +118,19 @@
                 ("erd", True),    # Correct
                 ("wrong", False)  # Incorrect
             )
-            record = (yield self.directory.recordWithShortName(RecordType.user, "dre"))
+            record = (
+                yield self.directory.recordWithShortName(RecordType.user, "dre")
+            )
         elif testMode == "od":
             expectations = (
                 (odpw, True),     # Correct
                 ("wrong", False)  # Incorrect
             )
-            record = (yield self.directory.recordWithGUID("D0B38B00-4166-11DD-B22C-A07C87F02F6A"))
+            record = (
+                yield self.directory.recordWithGUID(
+                    "D0B38B00-4166-11DD-B22C-A07C87F02F6A"
+                )
+            )
 
         for password, answer in expectations:
             authenticated = (yield record.verifyPlaintextPassword(password))
@@ -139,14 +145,20 @@
                 ("erd", True),    # Correct
                 ("wrong", False)  # Incorrect
             )
-            record = (yield self.directory.recordWithShortName(RecordType.user, "dre"))
+            record = (
+                yield self.directory.recordWithShortName(RecordType.user, "dre")
+            )
         elif testMode == "od":
             username = "sagen"
             expectations = (
                 (odpw, True),     # Correct
                 ("wrong", False)  # Incorrect
             )
-            record = (yield self.directory.recordWithGUID("D0B38B00-4166-11DD-B22C-A07C87F02F6A"))
+            record = (
+                yield self.directory.recordWithGUID(
+                    "D0B38B00-4166-11DD-B22C-A07C87F02F6A"
+                )
+            )
 
         realm = "host.example.com"
         nonce = "128446648710842461101646794502"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/b7c98af2/attachment.html>


More information about the calendarserver-changes mailing list