28 lines
794 B
Python
28 lines
794 B
Python
# coding=UTF-8
|
|
import json
|
|
from flask import request, current_app, Response
|
|
|
|
|
|
def check_api_key():
|
|
api_keys = current_app.config.get("API_KEYS")
|
|
if not api_keys:
|
|
return
|
|
auth = request.authorization
|
|
if not auth or not auth.username in api_keys:
|
|
response = json.dumps({"status": 401, "message": "No valid API key provided"})
|
|
return Response(
|
|
response, 401, {"WWW-Authenticate": 'Basic realm="Login Required"'}
|
|
)
|
|
|
|
|
|
def pagination_to_dict(pagination):
|
|
return {
|
|
"page": pagination.page,
|
|
"pages": pagination.pages,
|
|
"next_num": pagination.next_num,
|
|
"per_page": pagination.per_page,
|
|
"has_next": pagination.has_next,
|
|
"has_prev": pagination.has_prev,
|
|
"total": pagination.total,
|
|
}
|