[CalendarServer-changes] [745] CalendarServer/branches/caldavd-twistd-plugin-2

source_changes at macosforge.org source_changes at macosforge.org
Thu Dec 7 12:06:52 PST 2006


Revision: 745
          http://trac.macosforge.org/projects/calendarserver/changeset/745
Author:   dreid at apple.com
Date:     2006-12-07 12:06:52 -0800 (Thu, 07 Dec 2006)

Log Message:
-----------
Now serving CalDAV on tap.

Modified Paths:
--------------
    CalendarServer/branches/caldavd-twistd-plugin-2/conf/caldavd.plist
    CalendarServer/branches/caldavd-twistd-plugin-2/twistedcaldav/config.py

Added Paths:
-----------
    CalendarServer/branches/caldavd-twistd-plugin-2/twistedcaldav/tap.py

Modified: CalendarServer/branches/caldavd-twistd-plugin-2/conf/caldavd.plist
===================================================================
--- CalendarServer/branches/caldavd-twistd-plugin-2/conf/caldavd.plist	2006-12-07 18:40:30 UTC (rev 744)
+++ CalendarServer/branches/caldavd-twistd-plugin-2/conf/caldavd.plist	2006-12-07 20:06:52 UTC (rev 745)
@@ -105,5 +105,11 @@
   <key>SACLEnable</key>
   <true/>
 
+  <key>AuthSchemes</key>
+  <array>
+<!--     <string>Digest</string> -->
+    <string>Basic</string>
+  </array>
+
 </dict>
 </plist>

Modified: CalendarServer/branches/caldavd-twistd-plugin-2/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/caldavd-twistd-plugin-2/twistedcaldav/config.py	2006-12-07 18:40:30 UTC (rev 744)
+++ CalendarServer/branches/caldavd-twistd-plugin-2/twistedcaldav/config.py	2006-12-07 20:06:52 UTC (rev 745)
@@ -24,8 +24,9 @@
 
 DEFAULTS = {
     'CreateAccounts': False,
-    'DirectoryService': {'params': {'node': '/Search'},
-                         'type': 'OpenDirectoryService'},
+    'DirectoryService': {
+        'params': {'node': '/Search'},
+        'type': 'twistedcaldav.directory.appleopendirectory.OpenDirectoryService'},
     'DocumentRoot': '/Library/CalendarServer/Documents',
     'DropBoxEnabled': True,
     'DropBoxInheritedACLs': True,
@@ -51,6 +52,7 @@
     'Verbose': False,
     'twistdLocation': '/usr/share/caldavd/bin/twistd',
     'SACLEnable': True,
+    'AuthSchemes': ['Basic'],
 }
 
 globs = globals()

Added: CalendarServer/branches/caldavd-twistd-plugin-2/twistedcaldav/tap.py
===================================================================
--- CalendarServer/branches/caldavd-twistd-plugin-2/twistedcaldav/tap.py	                        (rev 0)
+++ CalendarServer/branches/caldavd-twistd-plugin-2/twistedcaldav/tap.py	2006-12-07 20:06:52 UTC (rev 745)
@@ -0,0 +1,163 @@
+##
+# Copyright (c) 2005-2006 Apple Computer, Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# DRI: David Reid, dreid at apple.com
+##
+
+import os
+import sys
+
+from zope.interface import implements
+
+from twisted.python.usage import Options
+from twisted.python.reflect import namedClass
+
+from twisted.application import internet, service
+from twisted.plugin import IPlugin
+
+from twisted.cred.portal import Portal
+
+from twisted.web2.dav import auth
+from twisted.web2.auth import basic
+from twisted.web2.channel import http
+
+from twisted.web2.tap import Web2Service
+from twisted.web2.log import LogWrapperResource
+from twisted.web2.server import Site
+
+from twistedcaldav import config
+from twistedcaldav.logging import RotatingFileAccessLoggingObserver
+from twistedcaldav.root import RootResource
+from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
+from twistedcaldav.static import CalendarHomeProvisioningFile
+
+
+class CaldavOptions(Options):
+    optParameters = [
+        ["config", "f", "/etc/caldavd/caldavd.plist",
+         "Path to configuration file."]
+        ]
+
+    zsh_actions = {"config" : "_files -g '*.plist'"}
+
+    def postOptions(self):
+        if not os.path.exists(self['config']):
+            print "Config file %s not found, using defaults" % (self['config'],)
+
+        config.parseConfig(self['config'])
+
+
+class CaldavServiceMaker(object):
+    implements(IPlugin, service.IServiceMaker)
+
+    tapname = "caldav"
+
+    description = "The Darwin Calendar Server"
+
+    options = CaldavOptions
+
+    def makeService(self, options):
+        #
+        # Setup the Directory
+        #
+
+        print config.DirectoryService
+
+        directoryClass = namedClass(config.DirectoryService['type'])
+
+        directory = directoryClass(**config.DirectoryService['params'])
+
+        #
+        # Setup Resource hierarchy
+        #
+
+        principalCollection = DirectoryPrincipalProvisioningResource(
+            os.path.join(config.DocumentRoot, 'principals'),
+            '/principals/',
+            directory
+            )
+
+        calendarCollection = CalendarHomeProvisioningFile(
+            os.path.join(config.DocumentRoot, 'calendars'),
+            directory,
+            '/calendars/')
+        
+        root = RootResource(config.DocumentRoot, 
+                            principalCollections=(principalCollection,)
+                            )
+
+        root.putChild('principals', principalCollection)
+        root.putChild('calendars', calendarCollection)
+
+        #
+        # Configure the Site and Wrappers
+        #
+
+        credentialFactories = []
+
+        portal = Portal(auth.DavRealm())
+
+        portal.registerChecker(directory)
+
+        # TODO: figure out the list of supported schemes from the directory
+        schemes = {'basic': basic.BasicCredentialFactory(""),
+                   #'digest': digest.DigestCredentialFactory
+                   }
+
+        for scheme in config.AuthSchemes:
+            scheme = scheme.lower()
+            
+            if scheme not in schemes:
+                print "Scheme not supported: %s" % (scheme,)
+                sys.exit(1)
+            else:
+                # TODO: limit basic scheme to SSL
+                credentialFactories.append(schemes[scheme])
+                
+        authWrapper = auth.AuthenticationWrapper(
+            root,
+            portal,
+            credentialFactories,
+            (auth.IPrincipal,))
+
+        site = Site(LogWrapperResource(authWrapper))
+
+        #
+        # Configure the service
+        # 
+
+        channel = http.HTTPFactory(site)
+
+        logObserver = RotatingFileAccessLoggingObserver(config.ServerLogFile)
+        
+        service = Web2Service(logObserver)
+
+        httpService = internet.TCPServer(
+            int(config.Port),
+            channel)
+
+        httpService.setServiceParent(service)
+
+        if config.SSLEnable:
+            from twisted.internet.ssl import DefaultOpenSSLContextFactory
+            httpsService = internet.SSLServer(
+                int(config.SSLPort),
+                channel,
+                DefaultOpenSSLContextFactory(config.SSLPrivateKey,
+                                             config.SSLCertificate))
+
+            httpsService.setServiceParent(service)
+            
+        return service

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061207/5ef35b1b/attachment.html


More information about the calendarserver-changes mailing list