24 lines
617 B
Python
24 lines
617 B
Python
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}) |