aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf/grumpy.cfg4
-rw-r--r--grumpy/utils.py33
-rw-r--r--grumpy/webapp.py8
3 files changed, 44 insertions, 1 deletions
diff --git a/conf/grumpy.cfg b/conf/grumpy.cfg
index b74ab79..89c8921 100644
--- a/conf/grumpy.cfg
+++ b/conf/grumpy.cfg
@@ -14,3 +14,7 @@ SQLALCHEMY_DATABASE_URI='postgresql://grumpy:grumpy@localhost/grumpy'
# Grumpy configuration
GRUMPY_PORTAGE_DIR='/usr/portage'
+
+# Username/password for tinderbox reports
+TINDERBOX_USER='tinder'
+TINDERBOX_PASS='box'
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
diff --git a/grumpy/webapp.py b/grumpy/webapp.py
index 5dd2be6..fa7381a 100644
--- a/grumpy/webapp.py
+++ b/grumpy/webapp.py
@@ -10,8 +10,9 @@
"""
from . import app
from .models import Category, Package
+from .utils import requires_auth_basic
-from flask import flash, redirect, render_template, url_for
+from flask import flash, jsonify, redirect, render_template, url_for
@app.route('/')
@app.route('/browse/')
@@ -39,3 +40,8 @@ def browse_pkg(cat, pkg):
return render_template('browse_pkg.html', cat=cat, pkg=package)
flash('Package "%s/%s" does not exist' % (cat, pkg))
return redirect(url_for('browse_cat', cat=cat))
+
+@app.route('/_api/1.0/tinderbox/')
+@requires_auth_basic
+def tinderbox_api():
+ return jsonify(dict(success=False))