Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/web.py

Issue 8327353: Crawler backend (Closed)
Patch Set: Created Sept. 27, 2012, 6:22 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« sitescripts/hg/bin/irchook.py ('K') | « sitescripts/hg/bin/irchook.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/web.py
===================================================================
--- a/sitescripts/web.py
+++ b/sitescripts/web.py
@@ -4,7 +4,11 @@
# version 2.0 (the "License"). You can obtain a copy of the License at
# http://mozilla.org/MPL/2.0/.
+import base64
+from sitescripts.utils import get_config
+
handlers = {}
+authenticated_users = {}
def url_handler(url):
def decorator(func):
@@ -17,8 +21,29 @@
raise Exception('A handler for url %s is already registered' % url)
handlers[url] = func
+def basic_auth(f):
Wladimir Palant 2012/09/27 07:34:17 This should accept an optional config_section para
Felix Dahlke 2012/09/27 09:26:24 Done. Somehow thought authenticate was used direct
+ return lambda environ, start_response: authenticate(f, environ, start_response)
+
+def authenticate(f, environ, start_response, config_section = "DEFAULT"):
+ if "HTTP_AUTHORIZATION" in environ:
+ auth = environ["HTTP_AUTHORIZATION"].split()
+ if len(auth) == 2:
+ if auth[0].lower() == "basic":
+ username, password = base64.b64decode(auth[1]).split(":")
+ config = get_config()
+ expected_username = config.get(config_section, "basic_auth_username")
+ expected_password = config.get(config_section, "basic_auth_password")
+ if username == expected_username and password == expected_password:
+ return f(environ, start_response)
+
+ realm = get_config().get("DEFAULT", "basic_auth_realm")
+ start_response("401 UNAUTHORIZED",
+ [("WWW-Authenticate", 'Basic realm="%s"' % realm)])
+ return ""
+
import openid.web.server
import subscriptions.web.fallback
+import crashes.web.submitCrash
import reports.web.submitReport
import reports.web.updateReport
import reports.web.showDigest
« sitescripts/hg/bin/irchook.py ('K') | « sitescripts/hg/bin/irchook.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld