the application was rewritten a bit to be more testable
This commit is contained in:
+1
-48
@@ -1,48 +1 @@
|
||||
from flask import Flask, jsonify, Response, request
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from esales.cluster import Cluster
|
||||
|
||||
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)
|
||||
|
||||
# eSales
|
||||
esales = Cluster(app.config.get("ESALES_URL"))
|
||||
|
||||
from api.views import designers, categories
|
||||
app.register_blueprint(designers.mod)
|
||||
app.register_blueprint(categories.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)
|
||||
from .core import *
|
||||
Reference in New Issue
Block a user