[CalendarServer-changes] [13068] CalendarServer/branches/users/sagen/move2who-4
source_changes at macosforge.org
source_changes at macosforge.org
Mon Mar 31 15:18:30 PDT 2014
Revision: 13068
http://trac.calendarserver.org//changeset/13068
Author: wsanchez at apple.com
Date: 2014-03-31 15:18:29 -0700 (Mon, 31 Mar 2014)
Log Message:
-----------
Move uidForAuthToken to txdav.who.wiki; get rid of calendarserver.platform.darwin.wiki.
Modified Paths:
--------------
CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py
CalendarServer/branches/users/sagen/move2who-4/txdav/who/wiki.py
Removed Paths:
-------------
CalendarServer/branches/users/sagen/move2who-4/calendarserver/platform/darwin/wiki.py
Deleted: CalendarServer/branches/users/sagen/move2who-4/calendarserver/platform/darwin/wiki.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/platform/darwin/wiki.py 2014-03-31 22:12:49 UTC (rev 13067)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/platform/darwin/wiki.py 2014-03-31 22:18:29 UTC (rev 13068)
@@ -1,84 +0,0 @@
-##
-# Copyright (c) 2012-2014 Apple 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.
-##
-
-
-from twext.python.log import Logger
-from twext.internet.gaiendpoint import GAIEndpoint
-from twext.internet.adaptendpoint import connect
-
-from twisted.web.client import HTTPPageGetter, HTTPClientFactory
-from twisted.internet import reactor
-from twisted.internet.defer import inlineCallbacks, returnValue
-
-import json
-
-log = Logger()
-
-
- at inlineCallbacks
-def uidForAuthToken(token, host="localhost", port=80):
- """
- Send a GET request to the web auth service to retrieve the user record
- uid associated with the provided auth token.
-
- @param token: An auth token, usually passed in via cookie when webcal
- makes a request.
- @type token: C{str}
- @return: deferred returning a uid (C{str}) if successful, or
- will raise WebAuthError otherwise.
- """
- url = "http://%s:%d/auth/verify?auth_token=%s" % (host, port, token,)
- jsonResponse = (yield _getPage(url, host, port))
- try:
- response = json.loads(jsonResponse)
- except Exception, e:
- log.error(
- "Error parsing JSON response from webauth: {resp} {error}",
- resp=jsonResponse, error=str(e)
- )
- raise WebAuthError("Could not look up token: %s" % (token,))
- if response["succeeded"]:
- returnValue(response["generated_uid"])
- else:
- raise WebAuthError("Could not look up token: %s" % (token,))
-
-
-
-def _getPage(url, host, port):
- """
- Fetch the body of the given url via HTTP, connecting to the given host
- and port.
-
- @param url: The URL to GET
- @type url: C{str}
- @param host: The hostname to connect to
- @type host: C{str}
- @param port: The port number to connect to
- @type port: C{int}
- @return: A deferred; upon 200 success the body of the response is returned,
- otherwise a twisted.web.error.Error is the result.
- """
- factory = HTTPClientFactory(url)
- factory.protocol = HTTPPageGetter
- connect(GAIEndpoint(reactor, host, port), factory)
- return factory.deferred
-
-
-
-class WebAuthError(RuntimeError):
- """
- Error in web auth
- """
Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py 2014-03-31 22:12:49 UTC (rev 13067)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py 2014-03-31 22:18:29 UTC (rev 13068)
@@ -19,7 +19,7 @@
"RootResource",
]
-from calendarserver.platform.darwin.wiki import uidForAuthToken
+from txdav.who.wiki import uidForAuthToken
from twext.python.log import Logger
from twisted.cred.error import LoginFailed, UnauthorizedLogin
from twisted.internet.defer import inlineCallbacks, returnValue, succeed
Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/wiki.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/wiki.py 2014-03-31 22:12:49 UTC (rev 13067)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/wiki.py 2014-03-31 22:18:29 UTC (rev 13068)
@@ -19,10 +19,11 @@
"""
__all__ = [
+ "WikiAccessLevel",
"DirectoryService",
- "WikiAccessLevel",
]
+import json
from twext.internet.adaptendpoint import connect
from twext.internet.gaiendpoint import GAIEndpoint
from twext.internet.gaiendpoint import MultiFailure
@@ -346,6 +347,42 @@
+class WebAuthError(RuntimeError):
+ """
+ Error in web auth
+ """
+
+
+
+ at inlineCallbacks
+def uidForAuthToken(token, host="localhost", port=80):
+ """
+ Send a GET request to the web auth service to retrieve the user record
+ uid associated with the provided auth token.
+
+ @param token: An auth token, usually passed in via cookie when webcal
+ makes a request.
+ @type token: C{str}
+ @return: deferred returning a uid (C{str}) if successful, or
+ will raise WebAuthError otherwise.
+ """
+ url = "http://%s:%d/auth/verify?auth_token=%s" % (host, port, token,)
+ jsonResponse = (yield _getPage(url, host, port))
+ try:
+ response = json.loads(jsonResponse)
+ except Exception, e:
+ log.error(
+ "Error parsing JSON response from webauth: {resp} {error}",
+ resp=jsonResponse, error=str(e)
+ )
+ raise WebAuthError("Could not look up token: %s" % (token,))
+ if response["succeeded"]:
+ returnValue(response["generated_uid"])
+ else:
+ raise WebAuthError("Could not look up token: %s" % (token,))
+
+
+
def accessForUserToWiki(user, wiki, host="localhost", port=4444):
"""
Send a GET request to the wiki collabd service to retrieve the access level
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140331/5459427a/attachment-0001.html>
More information about the calendarserver-changes
mailing list