import aiohttp from flask import Blueprint from flask import current_app from flask import request from werkzeug.exceptions import abort from capsulflask.db import get_model, my_exec_info_message bp = Blueprint("spoke", __name__, url_prefix="/spoke") def authorized_as_hub(id): auth_header_value = request.headers.get('Authorization').replace("Bearer ", "") return auth_header_value == current_app.config["HUB_TOKEN"] @bp.route("/heartbeat", methods=("POST")) def heartbeat(): if authorized_as_hub(id): # make request to hub-domain.com/hub/heartbeat/{current_app.config["SPOKE_HOST_ID"]} # succeed or fail based on whether the request succeeds or fails. pass else: current_app.logger.info(f"/hosts/heartbeat returned 401: invalid token") return abort(401, "invalid hub token")