Files
api2/api/__init__.py
T
2016-05-11 16:05:42 +02:00

44 lines
868 B
Python

from flask import Flask, jsonify, Response, request
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config.from_object('config')
def on_404(e):
return jsonify(dict(error='Not found')), 404
app.errorhandler(404)(on_404)
# SQLAlchemy
db = SQLAlchemy(app)
from api.views import designers
app.register_blueprint(designers.mod)
def check_authentication():
auth = request.authorization
if not auth:
return False
return auth.username in app.config.get("API_KEYS")
@app.before_request
def authenticate():
if not check_authentication():
return Response(
'No valid API key provided', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'}
)
@app.route("/")
def index():
data = {
"info": {
"api_version": "0.0.1"
}
}
return jsonify(data)