first commit
This commit is contained in:
24
app/blueprints/api.py
Normal file
24
app/blueprints/api.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
from flask import Blueprint, jsonify
|
||||
from flask_httpauth import HTTPTokenAuth
|
||||
|
||||
from utils.token_store import ApiKeyStore
|
||||
|
||||
api_bp = Blueprint("api", __name__)
|
||||
auth = HTTPTokenAuth(scheme="Bearer")
|
||||
|
||||
STORE_PATH = os.getenv("API_TOKEN_FILE", "data/api_tokens.yaml")
|
||||
store = ApiKeyStore(STORE_PATH, bcrypt_rounds=12)
|
||||
|
||||
@auth.verify_token
|
||||
def verify_token(token: str):
|
||||
return store.verify(token)
|
||||
|
||||
@auth.error_handler
|
||||
def auth_error(status):
|
||||
return jsonify({"error": "Unauthorized"}), status
|
||||
|
||||
@api_bp.route("/health", methods=["GET"])
|
||||
@auth.login_required
|
||||
def health():
|
||||
return jsonify({"healthy": True})
|
||||
7
app/blueprints/main.py
Normal file
7
app/blueprints/main.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
main_bp = Blueprint("main", __name__)
|
||||
|
||||
@main_bp.route("/")
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
Reference in New Issue
Block a user