aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriit Laes <plaes@plaes.org>2010-07-14 13:48:48 +0300
committerPriit Laes <plaes@plaes.org>2010-07-14 13:48:48 +0300
commit27e4b98cb3c5c0e90e6889d78c330bd02f82426d (patch)
tree2617c1d055a353094d1d2850e1f94b81724879a2 /grumpy/utils.py
parentAdded weekly report (diff)
downloadgsoc2010-grumpy-27e4b98cb3c5c0e90e6889d78c330bd02f82426d.tar.gz
gsoc2010-grumpy-27e4b98cb3c5c0e90e6889d78c330bd02f82426d.tar.bz2
gsoc2010-grumpy-27e4b98cb3c5c0e90e6889d78c330bd02f82426d.zip
Added basic authentication support for tinderbox reports
Diffstat (limited to 'grumpy/utils.py')
-rw-r--r--grumpy/utils.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/grumpy/utils.py b/grumpy/utils.py
new file mode 100644
index 0000000..a70fd95
--- /dev/null
+++ b/grumpy/utils.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+"""
+ grumpy.utils
+ ~~~~~~~~~~~~
+
+ Miscellaneous utils for authentication and pagination.
+
+ :copyright: (c) 2010 Priit Laes
+"""
+from flask import request, Response
+from functools import wraps
+
+from . import app
+
+def authenticate():
+ """Sends a 401 response that enables basic HTTP auth"""
+ return Response('Could not verify your access level for that URL.\n'
+ 'You have to login with proper credentials', 401,
+ {'WWW-Authenticate': 'Basic realm="Login required"'})
+
+def check_auth(username, password):
+ """Checks username password against ones stored in configuration."""
+ return username == app.config['TINDERBOX_USER'] and \
+ password == app.config['TINDERBOX_PASS']
+
+def requires_auth_basic(f):
+ @wraps(f)
+ def decorated(*args, **kwargs):
+ auth = request.authorization
+ if not auth or not check_auth(auth.username, auth.password):
+ return authenticate()
+ return f(*args, **kwargs)
+ return decorated