add hub-and-spoke diagrams to readme

This commit is contained in:
2021-01-02 19:07:43 -06:00
parent b991ec89d2
commit 0a379b74ad
7 changed files with 47 additions and 20 deletions

View File

@ -1,4 +1,5 @@
import aiohttp
from flask import Blueprint
from flask import current_app
from flask import request
@ -6,17 +7,19 @@ from werkzeug.exceptions import abort
from capsulflask.db import get_model, my_exec_info_message
bp = Blueprint("hosts", __name__, url_prefix="/hosts")
bp = Blueprint("spoke", __name__, url_prefix="/spoke")
def authorized_for_host(id):
def authorized_as_hub(id):
auth_header_value = request.headers.get('Authorization').replace("Bearer ", "")
return get_model().authorized_for_host(id, auth_header_value)
return auth_header_value == current_app.config["HUB_TOKEN"]
@bp.route("/heartbeat/<string:id>", methods=("POST"))
def heartbeat(id):
if authorized_for_host(id):
get_model().host_heartbeat(id)
@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/{id} returned 401: invalid token")
return abort(401, "invalid host id or token")
current_app.logger.info(f"/hosts/heartbeat returned 401: invalid token")
return abort(401, "invalid hub token")